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

Function binary_example2

examples/src/bson_examples.cpp:214–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214void binary_example2()
215{
216 std::vector<uint8_t> input = { 0x13,0x00,0x00,0x00, // Document has 19 bytes
217 0x05, // Binary data
218 0x70,0x44,0x00, // "pD"
219 0x05,0x00,0x00,0x00, // Length is 5
220 0x80, // Subtype is 128
221 0x48,0x65,0x6c,0x6c,0x6f, // 'H','e','l','l','o'
222 0x00 // terminating null
223 };
224
225 json j = bson::decode_bson<json>(input);
226 std::cout << "JSON:\n" << pretty_print(j) << "\n\n";
227
228 std::cout << "tag: " << j["pD"].tag() << "\n";
229 std::cout << "ext_tag: " << j["pD"].ext_tag() << "\n";
230 auto bytes = j["pD"].as<std::vector<uint8_t>>();
231 std::cout << "binary data: " << jsoncons::byte_string_view{ bytes } << "\n";
232}
233
234void decode_decimal128()
235{

Callers 1

mainFunction · 0.85

Calls 3

pretty_printFunction · 0.85
tagMethod · 0.45
ext_tagMethod · 0.45

Tested by

no test coverage detected