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

Function parse_cbor_number

example/cbor.cpp:172–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170 const unsigned char* first, const unsigned char* last, value& v );
171
172const unsigned char*
173parse_cbor_number(
174 const unsigned char* first, const unsigned char* last, unsigned char ch, std::uint64_t& n )
175{
176 unsigned char cv = ch & 31;
177
178 if( cv < 24 )
179 {
180 n = cv;
181 }
182 else if( cv == 24 )
183 {
184 ensure( 1, first, last );
185 n = *first++;
186 }
187 else if( cv == 25 )
188 {
189 ensure( 2, first, last );
190 n = boost::endian::load_big_u16( first );
191 first += 2;
192 }
193 else if( cv == 26 )
194 {
195 ensure( 4, first, last );
196 n = boost::endian::load_big_u32( first );
197 first += 4;
198 }
199 else if( cv == 27 )
200 {
201 ensure( 8, first, last );
202 n = boost::endian::load_big_u64( first );
203 first += 8;
204 }
205 else if( cv == 31 )
206 {
207 // infinite array/object
208 throw_format_error( "Infinite sequences aren't supported" );
209 }
210 else
211 {
212 throw_format_error( "Invalid minor type" );
213 }
214
215 return first;
216}
217
218const unsigned char*
219parse_cbor_string(

Callers 6

parse_cbor_stringFunction · 0.85
parse_cbor_arrayFunction · 0.85
parse_cbor_objectFunction · 0.85
parse_cbor_unsignedFunction · 0.85
parse_cbor_signedFunction · 0.85
parse_cbor_semantic_tagFunction · 0.85

Calls 2

ensureFunction · 0.85
throw_format_errorFunction · 0.85

Tested by

no test coverage detected