26{
27 std::cout << "=== Serialization Formats Example ===" << std::endl;
28
29
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);
35
36 std::cout << "\n1. Original container:" << std::endl;
37 std::cout << " Fields: name, age, score, active" << std::endl;
38
39
40 std::cout << "\n2. Binary serialization:" << std::endl;
41 auto binary = serializer_factory::create(serialization_format::binary);
42 if (binary)
43 {
44 auto result = binary->serialize(container);
45 if (result.is_ok())
46 {
47 std::cout << " Size: " << result.value().size() << " bytes" << std::endl;
48 }
49 std::cout << " Format: " << binary->name() << std::endl;
50 }
51
52
53 std::cout << "\n3. JSON serialization:" << std::endl;
54 auto json = serializer_factory::create(serialization_format::json);
55 if (json)
56 {
57 auto result = json->serialize(container);
58 if (result.is_ok())
59 {
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;
64 }
65 }
66
67
68 std::cout << "\n4. Format support:" << std::endl;
69 std::cout << " Binary: "
70 << (serializer_factory::is_supported(serialization_format::binary) ? "yes" : "no")
71 << std::endl;
72 std::cout << " JSON: "
73 << (serializer_factory::is_supported(serialization_format::json) ? "yes" : "no")
74 << std::endl;
75
76 std::cout << "\nDone." << std::endl;
77 return 0;
78}