27 std::cout <<
"=== Serialization Formats Example ===" << std::endl;
30 value_container container;
31 container.set(
"name",
"Alice");
32 container.set(
"age",
static_cast<int64_t
>(30));
33 container.set(
"score", 95.5);
34 container.set(
"active",
true);
36 std::cout <<
"\n1. Original container:" << std::endl;
37 std::cout <<
" Fields: name, age, score, active" << std::endl;
40 std::cout <<
"\n2. Binary serialization:" << std::endl;
41 auto binary = serializer_factory::create(serialization_format::binary);
44 auto result = binary->serialize(container);
47 std::cout <<
" Size: " << result.value().size() <<
" bytes" << std::endl;
49 std::cout <<
" Format: " << binary->name() << std::endl;
53 std::cout <<
"\n3. JSON serialization:" << std::endl;
54 auto json = serializer_factory::create(serialization_format::json);
57 auto result = json->serialize(container);
60 auto& data = result.value();
61 std::string str(data.begin(), data.end());
62 std::cout <<
" Size: " << str.size() <<
" bytes" << std::endl;
63 std::cout <<
" Preview: " << str.substr(0, 80) <<
"..." << std::endl;
68 std::cout <<
"\n4. Format support:" << std::endl;
69 std::cout <<
" Binary: "
70 << (serializer_factory::is_supported(serialization_format::binary) ?
"yes" :
"no")
72 std::cout <<
" JSON: "
73 << (serializer_factory::is_supported(serialization_format::json) ?
"yes" :
"no")
76 std::cout <<
"\nDone." << std::endl;