29 std::string
to_json(
const std::vector<std::vector<T>>& chunks) {
30 validate_chunks(chunks);
33 std::string result =
"[";
34 for (
size_t i = 0; i < chunks.size(); ++i) {
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) {
43 if (i < chunks.size() - 1) {
57 std::string
to_protobuf(
const std::vector<std::vector<T>>& chunks) {
58 validate_chunks(chunks);
59 throw std::runtime_error(
"Protocol Buffers serialization not implemented");
68 std::string
to_msgpack(
const std::vector<std::vector<T>>& chunks) {
69 validate_chunks(chunks);
72 std::string result =
"[";
73 for (
size_t i = 0; i < chunks.size(); ++i) {
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) {
82 if (i < chunks.size() - 1) {
98 throw std::invalid_argument(
"Cannot serialize empty chunks");
101 for (
const auto& chunk : chunks) {
103 throw std::invalid_argument(
"Cannot serialize chunks containing empty vectors");
Class for serializing chunks to various formats.
std::string to_msgpack(const std::vector< std::vector< T > > &chunks)
Serialize chunks to MessagePack format.
void validate_chunks(const std::vector< std::vector< T > > &chunks)
Validate chunk data before serialization.
std::string to_protobuf(const std::vector< std::vector< T > > &chunks)
Serialize chunks to Protocol Buffers format.
std::string to_json(const std::vector< std::vector< T > > &chunks)
Serialize chunks to JSON format.