| 57 | } |
| 58 | |
| 59 | void data_model_example2() |
| 60 | { |
| 61 | std::vector<uint8_t> bytes; |
| 62 | cbor::cbor_bytes_encoder encoder(bytes); |
| 63 | encoder.begin_array(); // indefinite length outer array |
| 64 | encoder.string_value("foo"); |
| 65 | encoder.byte_string_value(byte_string{'b','a','r'}); |
| 66 | encoder.string_value("-18446744073709551617", semantic_tag::bigint); |
| 67 | encoder.string_value("273.15", semantic_tag::bigdec); |
| 68 | encoder.string_value("2018-10-19 12:41:07-07:00", semantic_tag::datetime) ; |
| 69 | encoder.int64_value(1431027667, semantic_tag::epoch_second); |
| 70 | encoder.int64_value(-1431027667, semantic_tag::epoch_second); |
| 71 | encoder.double_value(1431027667.5, semantic_tag::epoch_second); |
| 72 | encoder.end_array(); |
| 73 | encoder.flush(); |
| 74 | |
| 75 | std::cout << "(1)\n" << byte_string_view(bytes) << "\n\n"; |
| 76 | |
| 77 | /* |
| 78 | 9f -- Start indefinite length array |
| 79 | 63 -- String value of length 3 |
| 80 | 666f6f -- "foo" |
| 81 | 43 -- Byte string value of length 3 |
| 82 | 626172 -- 'b''a''r' |
| 83 | c3 -- Tag 3 (negative bignum) |
| 84 | 49 Byte string value of length 9 |
| 85 | 010000000000000000 -- Bytes content |
| 86 | c4 - Tag 4 (decimal fraction) |
| 87 | 82 -- Array of length 2 |
| 88 | 21 -- -2 |
| 89 | 19 6ab3 -- 27315 |
| 90 | c0 -- Tag 0 (date-time) |
| 91 | 78 19 -- Length (25) |
| 92 | 323031382d31302d31392031323a34313a30372d30373a3030 -- "2018-10-19 12:41:07-07:00" |
| 93 | c1 -- Tag 1 (epoch time) |
| 94 | 1a -- uint32_t |
| 95 | 554bbfd3 -- 1431027667 |
| 96 | c1 |
| 97 | 3a |
| 98 | 554bbfd2 |
| 99 | c1 |
| 100 | fb |
| 101 | 41d552eff4e00000 |
| 102 | ff -- "break" |
| 103 | */ |
| 104 | |
| 105 | json j = cbor::decode_cbor<json>(bytes); |
| 106 | |
| 107 | std::cout << "(2)\n" << pretty_print(j) << "\n\n"; |
| 108 | } |
| 109 | |
| 110 | int main() |
| 111 | { |
no test coverage detected