| 253 | } |
| 254 | |
| 255 | void encode_cbor_with_packed_strings() |
| 256 | { |
| 257 | ojson j = ojson::parse(R"( |
| 258 | [ |
| 259 | { |
| 260 | "name" : "Cocktail", |
| 261 | "count" : 417, |
| 262 | "rank" : 4 |
| 263 | }, |
| 264 | { |
| 265 | "rank" : 4, |
| 266 | "count" : 312, |
| 267 | "name" : "Bath" |
| 268 | }, |
| 269 | { |
| 270 | "count" : 691, |
| 271 | "name" : "Food", |
| 272 | "rank" : 4 |
| 273 | } |
| 274 | ] |
| 275 | )"); |
| 276 | |
| 277 | auto options = cbor::cbor_options{} |
| 278 | .pack_strings(true); |
| 279 | std::vector<uint8_t> buf; |
| 280 | |
| 281 | cbor::encode_cbor(j, buf, options); |
| 282 | |
| 283 | std::cout << byte_string_view(buf)<< "\n\n"; |
| 284 | |
| 285 | /* |
| 286 | d90100 -- tag (256) |
| 287 | 83 -- array(3) |
| 288 | a3 -- map(3) |
| 289 | 64 -- text string (4) |
| 290 | 6e616d65 -- "name" |
| 291 | 68 -- text string (8) |
| 292 | 436f636b7461696c -- "Cocktail" |
| 293 | 65 -- text string (5) |
| 294 | 636f756e74 -- "count" |
| 295 | 1901a1 -- unsigned(417) |
| 296 | 64 -- text string (4) |
| 297 | 72616e6b -- "rank" |
| 298 | 04 -- unsigned(4) |
| 299 | a3 -- map(3) |
| 300 | d819 -- tag(25) |
| 301 | 03 -- unsigned(3) |
| 302 | 04 -- unsigned(4) |
| 303 | d819 -- tag(25) |
| 304 | 02 -- unsigned(2) |
| 305 | 190138 -- unsigned(312) |
| 306 | d819 -- tag(25) |
| 307 | 00 -- unsigned(0) |
| 308 | 64 -- text string(4) |
| 309 | 42617468 -- "Bath" |
| 310 | a3 -- map(3) |
| 311 | d819 -- tag(25) |
| 312 | 02 -- unsigned(2) |
no test coverage detected