Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
chunk_serialization::ChunkSerializer< T > Class Template Reference

Class for serializing chunks to various formats. More...

#include <chunk_serialization.hpp>

Public Member Functions

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.
 

Private Member Functions

void validate_chunks (const std::vector< std::vector< T > > &chunks)
 Validate chunk data before serialization.
 

Detailed Description

template<typename T>
class chunk_serialization::ChunkSerializer< T >

Class for serializing chunks to various formats.

Template Parameters
TThe data type of the chunks

Definition at line 21 of file chunk_serialization.hpp.

Member Function Documentation

◆ to_json()

template<typename T >
std::string chunk_serialization::ChunkSerializer< T >::to_json ( const std::vector< std::vector< T > > &  chunks)
inline

Serialize chunks to JSON format.

Parameters
chunksVector of chunk data
Returns
JSON string representation
Exceptions
std::runtime_errorif serialization fails

Definition at line 29 of file chunk_serialization.hpp.

29 {
30 validate_chunks(chunks);
31
32 // Basic JSON array serialization
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()

template<typename T >
std::string chunk_serialization::ChunkSerializer< T >::to_msgpack ( const std::vector< std::vector< T > > &  chunks)
inline

Serialize chunks to MessagePack format.

Parameters
chunksVector of chunk data
Returns
MessagePack binary string
Exceptions
std::runtime_errorif MessagePack support not available

Definition at line 68 of file chunk_serialization.hpp.

68 {
69 validate_chunks(chunks);
70
71 // Basic implementation without MessagePack dependency
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()

template<typename T >
std::string chunk_serialization::ChunkSerializer< T >::to_protobuf ( const std::vector< std::vector< T > > &  chunks)
inline

Serialize chunks to Protocol Buffers format.

Parameters
chunksVector of chunk data
Returns
Protobuf binary string
Exceptions
std::runtime_errorif Protobuf support not available

Definition at line 57 of file chunk_serialization.hpp.

57 {
58 validate_chunks(chunks);
59 throw std::runtime_error("Protocol Buffers serialization not implemented");
60 }

◆ validate_chunks()

template<typename T >
void chunk_serialization::ChunkSerializer< T >::validate_chunks ( const std::vector< std::vector< T > > &  chunks)
inlineprivate

Validate chunk data before serialization.

Parameters
chunksVector of chunk data to validate
Exceptions
std::invalid_argumentif 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: