MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / read_value

Function read_value

nodedb-query/src/msgpack_scan/reader.rs:378–424  ·  view source on GitHub ↗

Read a scalar msgpack value at `offset` into `nodedb_types::Value`. Handles null, bool, integers, floats, and strings. For complex types (array, map, bin, ext), returns `None` — caller should use `json_from_msgpack` for those.

(buf: &[u8], offset: usize)

Source from the content-addressed store, hash-verified

376/// (array, map, bin, ext), returns `None` — caller should use
377/// `json_from_msgpack` for those.
378pub fn read_value(buf: &[u8], offset: usize) -> Option<nodedb_types::Value> {
379 let tag = get(buf, offset)?;
380 match tag {
381 NIL => Some(nodedb_types::Value::Null),
382 TRUE => Some(nodedb_types::Value::Bool(true)),
383 FALSE => Some(nodedb_types::Value::Bool(false)),
384 // Integers
385 0x00..=0x7f => Some(nodedb_types::Value::Integer(tag as i64)),
386 0xe0..=0xff => Some(nodedb_types::Value::Integer((tag as i8) as i64)),
387 UINT8 => Some(nodedb_types::Value::Integer(get(buf, offset + 1)? as i64)),
388 UINT16 => Some(nodedb_types::Value::Integer(
389 read_u16_be(buf, offset + 1)? as i64
390 )),
391 UINT32 => Some(nodedb_types::Value::Integer(
392 read_u32_be(buf, offset + 1)? as i64
393 )),
394 UINT64 => Some(nodedb_types::Value::Integer(
395 read_u64_be(buf, offset + 1)? as i64
396 )),
397 INT8 => Some(nodedb_types::Value::Integer(
398 get(buf, offset + 1)? as i8 as i64
399 )),
400 INT16 => Some(nodedb_types::Value::Integer(
401 read_u16_be(buf, offset + 1)? as i16 as i64,
402 )),
403 INT32 => Some(nodedb_types::Value::Integer(
404 read_u32_be(buf, offset + 1)? as i32 as i64,
405 )),
406 INT64 => Some(nodedb_types::Value::Integer(
407 read_u64_be(buf, offset + 1)? as i64
408 )),
409 // Floats
410 FLOAT32 => {
411 let bits = read_u32_be(buf, offset + 1)?;
412 Some(nodedb_types::Value::Float(f32::from_bits(bits) as f64))
413 }
414 FLOAT64 => {
415 let bits = read_u64_be(buf, offset + 1)?;
416 Some(nodedb_types::Value::Float(f64::from_bits(bits)))
417 }
418 // Strings
419 0xa0..=0xbf | STR8 | STR16 | STR32 => {
420 read_str(buf, offset).map(|s| nodedb_types::Value::String(s.to_string()))
421 }
422 _ => None,
423 }
424}
425
426/// Return the number of key-value pairs and the offset of the first pair,
427/// for the map starting at `offset`. Returns `None` if not a map.

Callers 11

eval_opFunction · 0.70
eq_valueFunction · 0.70
cmp_valueFunction · 0.70
extract_valueFunction · 0.70
value_from_fieldFunction · 0.70
find_minmaxFunction · 0.70
fuzz_two_byte_patternsFunction · 0.70

Calls 6

getFunction · 0.85
read_u16_beFunction · 0.85
read_u32_beFunction · 0.85
read_u64_beFunction · 0.85
to_stringMethod · 0.80
read_strFunction · 0.70