| 15 | namespace bson = jsoncons::bson; // for brevity |
| 16 | |
| 17 | void 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 | |
| 52 | void subtype_example() |
| 53 | { |
no test coverage detected