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

Function decode_fixed_value

nodedb-strict/src/decode.rs:397–442  ·  view source on GitHub ↗

Decode a fixed-size raw byte slice into a Value.

(col_type: &ColumnType, raw: &[u8])

Source from the content-addressed store, hash-verified

395
396/// Decode a fixed-size raw byte slice into a Value.
397fn decode_fixed_value(col_type: &ColumnType, raw: &[u8]) -> Value {
398 match col_type {
399 ColumnType::Int64 => Value::Integer(i64::from_le_bytes([
400 raw[0], raw[1], raw[2], raw[3], raw[4], raw[5], raw[6], raw[7],
401 ])),
402 ColumnType::Float64 => Value::Float(f64::from_le_bytes([
403 raw[0], raw[1], raw[2], raw[3], raw[4], raw[5], raw[6], raw[7],
404 ])),
405 ColumnType::Bool => Value::Bool(raw[0] != 0),
406 ColumnType::Timestamp => {
407 let micros = i64::from_le_bytes([
408 raw[0], raw[1], raw[2], raw[3], raw[4], raw[5], raw[6], raw[7],
409 ]);
410 Value::NaiveDateTime(NdbDateTime::from_micros(micros))
411 }
412 ColumnType::Timestamptz => {
413 let micros = i64::from_le_bytes([
414 raw[0], raw[1], raw[2], raw[3], raw[4], raw[5], raw[6], raw[7],
415 ]);
416 Value::DateTime(NdbDateTime::from_micros(micros))
417 }
418 ColumnType::Decimal { .. } => {
419 let mut bytes = [0u8; 16];
420 bytes.copy_from_slice(&raw[..16]);
421 Value::Decimal(rust_decimal::Decimal::deserialize(bytes))
422 }
423 ColumnType::Uuid => {
424 let mut bytes = [0u8; 16];
425 bytes.copy_from_slice(&raw[..16]);
426 let parsed = uuid::Uuid::from_bytes(bytes);
427 Value::Uuid(parsed.to_string())
428 }
429 ColumnType::Vector(dim) => {
430 let d = *dim as usize;
431 let mut floats = Vec::with_capacity(d);
432 for i in 0..d {
433 let off = i * 4;
434 let bytes = [raw[off], raw[off + 1], raw[off + 2], raw[off + 3]];
435 let f = f32::from_le_bytes(bytes);
436 floats.push(Value::Float(f as f64));
437 }
438 Value::Array(floats)
439 }
440 _ => Value::Null, // Unreachable for fixed types.
441 }
442}
443
444/// Decode a variable-length raw byte slice into a Value.
445fn decode_variable_value(col_type: &ColumnType, raw: &[u8]) -> Value {

Callers 1

extract_valueMethod · 0.85

Calls 3

deserializeFunction · 0.85
to_stringMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected