MCPcopy Create free account
hub / github.com/boostorg/json / serialize_cbor_number

Function serialize_cbor_number

example/cbor.cpp:25–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23using namespace boost::json;
24
25void serialize_cbor_number(
26 unsigned char mt, std::uint64_t n, std::vector<unsigned char> & out )
27{
28 mt <<= 5;
29
30 if( n < 24 )
31 {
32 out.push_back( static_cast<unsigned char>( mt + n ) );
33 }
34 else if( n < 256 )
35 {
36 unsigned char data[] = { static_cast<unsigned char>( mt + 24 ), static_cast<unsigned char>( n ) };
37 out.insert( out.end(), std::begin( data ), std::end( data ) );
38 }
39 else if( n < 65536 )
40 {
41 unsigned char data[] = { static_cast<unsigned char>( mt + 25 ), static_cast<unsigned char>( n >> 8 ), static_cast<unsigned char>( n ) };
42 out.insert( out.end(), std::begin( data ), std::end( data ) );
43 }
44 else if( n < 0x1000000ull )
45 {
46 unsigned char data[ 5 ];
47
48 data[ 0 ] = static_cast<unsigned char>( mt + 26 );
49 boost::endian::endian_store<std::uint32_t, 4, boost::endian::order::big>( data + 1, static_cast<std::uint32_t>( n ) );
50
51 out.insert( out.end(), std::begin( data ), std::end( data ) );
52 }
53 else
54 {
55 unsigned char data[ 9 ];
56
57 data[ 0 ] = static_cast<unsigned char>( mt + 27 );
58 boost::endian::endian_store<std::uint64_t, 8, boost::endian::order::big>( data + 1, n );
59
60 out.insert( out.end(), std::begin( data ), std::end( data ) );
61 }
62}
63
64void
65serialize_cbor_string( string_view sv, std::vector<unsigned char>& out )

Callers 2

serialize_cbor_stringFunction · 0.85
serialize_cbor_valueFunction · 0.85

Calls 3

push_backMethod · 0.45
insertMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected