| 187 | } |
| 188 | |
| 189 | void query_cbor() |
| 190 | { |
| 191 | // Construct a json array of numbers |
| 192 | json j(json_array_arg); |
| 193 | |
| 194 | j.emplace_back(5.0); |
| 195 | |
| 196 | j.emplace_back(0.000071); |
| 197 | |
| 198 | j.emplace_back("-18446744073709551617",semantic_tag::bigint); |
| 199 | |
| 200 | j.emplace_back("1.23456789012345678901234567890", semantic_tag::bigdec); |
| 201 | |
| 202 | j.emplace_back("0x3p-1", semantic_tag::bigfloat); |
| 203 | |
| 204 | // Encode to JSON |
| 205 | std::cout << "(1)\n"; |
| 206 | std::cout << pretty_print(j); |
| 207 | std::cout << "\n\n"; |
| 208 | |
| 209 | // as<std::string>() and as<double>() |
| 210 | std::cout << "(2)\n"; |
| 211 | std::cout << std::dec << std::setprecision(15); |
| 212 | for (const auto& item : j.array_range()) |
| 213 | { |
| 214 | std::cout << item.as<std::string>() << ", " << item.as<double>() << "\n"; |
| 215 | } |
| 216 | std::cout << "\n"; |
| 217 | |
| 218 | // Encode to CBOR |
| 219 | std::vector<uint8_t> v; |
| 220 | cbor::encode_cbor(j,v); |
| 221 | |
| 222 | std::cout << "(3)\n" << byte_string_view(v) << "\n\n"; |
| 223 | /* |
| 224 | 85 -- Array of length 5 |
| 225 | fa -- float |
| 226 | 40a00000 -- 5.0 |
| 227 | fb -- double |
| 228 | 3f129cbab649d389 -- 0.000071 |
| 229 | c3 -- Tag 3 (negative bignum) |
| 230 | 49 -- Byte string value of length 9 |
| 231 | 010000000000000000 |
| 232 | c4 -- Tag 4 (decimal fraction) |
| 233 | 82 -- Array of length 2 |
| 234 | 38 -- Negative integer of length 1 |
| 235 | 1c -- -29 |
| 236 | c2 -- Tag 2 (positive bignum) |
| 237 | 4d -- Byte string value of length 13 |
| 238 | 018ee90ff6c373e0ee4e3f0ad2 |
| 239 | c5 -- Tag 5 (bigfloat) |
| 240 | 82 -- Array of length 2 |
| 241 | 20 -- -1 |
| 242 | 03 -- 3 |
| 243 | */ |
| 244 | |
| 245 | // Decode back to json |
| 246 | json other = cbor::decode_cbor<json>(v); |
no test coverage detected