Class for serializing chunks to various formats.
More...
#include <chunk_serialization.hpp>
|
| std::string | to_json (const std::vector< std::vector< T > > &chunks) |
| | Serialize chunks to JSON format.
|
| |
| std::string | to_msgpack (const std::vector< std::vector< T > > &chunks) |
| | Serialize chunks to MessagePack format.
|
| |
| std::string | to_protobuf (const std::vector< std::vector< T > > &chunks) |
| | Serialize chunks to Protocol Buffers format.
|
| |
|
| void | validate_chunks (const std::vector< std::vector< T > > &chunks) |
| | Validate chunk data before serialization.
|
| |
template<typename T>
class chunk_serialization::ChunkSerializer< T >
Class for serializing chunks to various formats.
- Template Parameters
-
| T | The data type of the chunks |
Definition at line 21 of file chunk_serialization.hpp.
◆ to_json()
Serialize chunks to JSON format.
- Parameters
-
| chunks | Vector of chunk data |
- Returns
- JSON string representation
- Exceptions
-
| std::runtime_error | if serialization fails |
Definition at line 29 of file chunk_serialization.hpp.
29 {
31
32
33 std::string result = "[";
34 for (size_t i = 0; i < chunks.size(); ++i) {
35 result += "[";
36 for (size_t j = 0; j < chunks[i].size(); ++j) {
37 result += std::to_string(chunks[i][j]);
38 if (j < chunks[i].size() - 1) {
39 result += ",";
40 }
41 }
42 result += "]";
43 if (i < chunks.size() - 1) {
44 result += ",";
45 }
46 }
47 result += "]";
48 return result;
49 }
void validate_chunks(const std::vector< std::vector< T > > &chunks)
Validate chunk data before serialization.
Referenced by TEST_F().
◆ to_msgpack()
Serialize chunks to MessagePack format.
- Parameters
-
| chunks | Vector of chunk data |
- Returns
- MessagePack binary string
- Exceptions
-
| std::runtime_error | if MessagePack support not available |
Definition at line 68 of file chunk_serialization.hpp.
68 {
70
71
72 std::string result = "[";
73 for (size_t i = 0; i < chunks.size(); ++i) {
74 result += "[";
75 for (size_t j = 0; j < chunks[i].size(); ++j) {
76 result += std::to_string(chunks[i][j]);
77 if (j < chunks[i].size() - 1) {
78 result += ",";
79 }
80 }
81 result += "]";
82 if (i < chunks.size() - 1) {
83 result += ",";
84 }
85 }
86 result += "]";
87 return result;
88 }
◆ to_protobuf()
Serialize chunks to Protocol Buffers format.
- Parameters
-
| chunks | Vector of chunk data |
- Returns
- Protobuf binary string
- Exceptions
-
| std::runtime_error | if Protobuf support not available |
Definition at line 57 of file chunk_serialization.hpp.
57 {
59 throw std::runtime_error("Protocol Buffers serialization not implemented");
60 }
◆ validate_chunks()
Validate chunk data before serialization.
- Parameters
-
| chunks | Vector of chunk data to validate |
- Exceptions
-
| std::invalid_argument | if validation fails |
Definition at line 96 of file chunk_serialization.hpp.
96 {
97 if (chunks.empty()) {
98 throw std::invalid_argument("Cannot serialize empty chunks");
99 }
100
101 for (const auto& chunk : chunks) {
102 if (chunk.empty()) {
103 throw std::invalid_argument("Cannot serialize chunks containing empty vectors");
104 }
105 }
106 }
The documentation for this class was generated from the following file: