MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / ext_example

Function ext_example

examples/src/msgpack_examples.cpp:90–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90void ext_example()
91{
92 std::vector<uint8_t> input = {
93
94 0x82, // map, length 2
95 0xa5, // string, length 5
96 'H','e','l','l','o',
97 0xa5, // string, length 5
98 'W','o','r','l','d',
99 0xa4, // string, length 4
100 'D','a','t','a',
101 0xc7, // ext8 format code
102 0x06, // length 6
103 0x07, // type
104 'f','o','o','b','a','r'
105 };
106
107 ojson j = msgpack::decode_msgpack<ojson>(input);
108
109 std::cout << "(1)\n" << pretty_print(j) << "\n\n";
110 std::cout << "(2) " << j["Data"].tag() << "(" << j["Data"].ext_tag() << ")\n\n";
111
112 // Get ext value as a std::vector<uint8_t>
113 auto v = j["Data"].as<std::vector<uint8_t>>();
114
115 std::cout << "(3)\n";
116 std::cout << jsoncons::byte_string_view(v) << "\n\n";
117
118 std::vector<uint8_t> output;
119 msgpack::encode_msgpack(j,output);
120 assert(output == input);
121}
122
123void duration_example1()
124{

Callers 1

mainFunction · 0.85

Calls 5

pretty_printFunction · 0.85
byte_string_viewClass · 0.85
encode_msgpackFunction · 0.85
tagMethod · 0.45
ext_tagMethod · 0.45

Tested by

no test coverage detected