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

Function encode_to_bson

examples/src/bson_examples.cpp:17–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15namespace bson = jsoncons::bson; // for brevity
16
17void encode_to_bson()
18{
19 std::vector<uint8_t> buffer;
20 bson::bson_bytes_encoder encoder(buffer);
21 encoder.begin_array(); // The total number of bytes comprising
22 // the bson document will be calculated
23 encoder.string_value("cat");
24 std::vector<uint8_t> purr = {'p','u','r','r'};
25 encoder.byte_string_value(purr); // default subtype is user defined
26 // or encoder.byte_string_value(purr, 0x80);
27 encoder.int64_value(1431027667, jsoncons::semantic_tag::epoch_second);
28 encoder.end_array();
29 encoder.flush();
30
31 std::cout << jsoncons::byte_string_view(buffer) << "\n\n";
32
33/*
34 23000000 -- Total number of bytes comprising the document (35 bytes)
35 02 -- UTF-8 string
36 3000 -- "0"
37 04000000 -- number bytes in the string (including trailing byte)
38 636174 -- "cat"
39 00 -- trailing byte
40 05 -- binary
41 3100 -- "1"
42 04000000 -- number of bytes
43 80 -- subtype
44 70757272 -- 'P','u','r','r'
45 09 -- datetime
46 3200 -- "2"
47 d3bf4b55 -- 1431027667
48 00
49*/
50}
51
52void subtype_example()
53{

Callers 1

mainFunction · 0.85

Calls 7

byte_string_viewClass · 0.85
begin_arrayMethod · 0.45
string_valueMethod · 0.45
byte_string_valueMethod · 0.45
int64_valueMethod · 0.45
end_arrayMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected