MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / encode_to_cbor_buffer

Function encode_to_cbor_buffer

examples/src/cbor_examples.cpp:18–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16using namespace jsoncons;
17
18void 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
51void encode_to_cbor_stream()
52{

Callers 1

mainFunction · 0.85

Calls 7

byte_string_viewClass · 0.85
begin_arrayMethod · 0.45
string_valueMethod · 0.45
byte_string_valueMethod · 0.45
int64_valueMethod · 0.45
end_arrayMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected