| 16 | using namespace jsoncons; |
| 17 | |
| 18 | void encode_to_cbor_buffer() |
| 19 | { |
| 20 | std::vector<uint8_t> buffer; |
| 21 | cbor::cbor_bytes_encoder encoder(buffer); |
| 22 | |
| 23 | encoder.begin_array(); // Indefinite length array |
| 24 | encoder.string_value("cat"); |
| 25 | std::vector<uint8_t> purr = {'p','u','r','r'}; |
| 26 | encoder.byte_string_value(purr); |
| 27 | std::vector<uint8_t> hiss = {'h','i','s','s'}; |
| 28 | encoder.byte_string_value(hiss, semantic_tag::base64); // suggested conversion to base64 |
| 29 | encoder.int64_value(1431027667, semantic_tag::epoch_second); |
| 30 | encoder.end_array(); |
| 31 | encoder.flush(); |
| 32 | |
| 33 | std::cout << byte_string_view(buffer) << "\n\n"; |
| 34 | |
| 35 | /* |
| 36 | 9f -- Start indefinte length array |
| 37 | 63 -- String value of length 3 |
| 38 | 636174 -- "cat" |
| 39 | 44 -- Byte string value of length 4 |
| 40 | 70757272 -- 'p''u''r''r' |
| 41 | d6 - Expected conversion to base64 |
| 42 | 44 |
| 43 | 68697373 -- 'h''i''s''s' |
| 44 | c1 -- Tag value 1 (seconds relative to 1970-01-01T00:00Z in UTC time) |
| 45 | 1a -- 32 bit unsigned integer |
| 46 | 554bbfd3 -- 1431027667 |
| 47 | ff -- "break" |
| 48 | */ |
| 49 | } |
| 50 | |
| 51 | void encode_to_cbor_stream() |
| 52 | { |
no test coverage detected