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

Function read_f64

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

Read an f64 from the value at `offset`. Handles float32, float64, and all integer types (coerced to f64).

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

Source from the content-addressed store, hash-verified

214/// Read an f64 from the value at `offset`. Handles float32, float64,
215/// and all integer types (coerced to f64).
216pub fn read_f64(buf: &[u8], offset: usize) -> Option<f64> {
217 let tag = get(buf, offset)?;
218 match tag {
219 // positive fixint
220 0x00..=0x7f => Some(tag as f64),
221 // negative fixint
222 0xe0..=0xff => Some((tag as i8) as f64),
223 FLOAT64 => {
224 let bits = read_u64_be(buf, offset + 1)?;
225 Some(f64::from_bits(bits))
226 }
227 FLOAT32 => {
228 let bits = read_u32_be(buf, offset + 1)?;
229 Some(f32::from_bits(bits) as f64)
230 }
231 UINT8 => Some(get(buf, offset + 1)? as f64),
232 UINT16 => Some(read_u16_be(buf, offset + 1)? as f64),
233 UINT32 => Some(read_u32_be(buf, offset + 1)? as f64),
234 UINT64 => Some(read_u64_be(buf, offset + 1)? as f64),
235 INT8 => Some(get(buf, offset + 1)? as i8 as f64),
236 INT16 => Some(read_u16_be(buf, offset + 1)? as i16 as f64),
237 INT32 => Some(read_u32_be(buf, offset + 1)? as i32 as f64),
238 INT64 => Some(read_u64_be(buf, offset + 1)? as i64 as f64),
239 _ => None,
240 }
241}
242
243/// Read an i64 from the value at `offset`. Handles all integer types.
244/// Floats return `None` — use `read_f64` for those.

Callers 13

extract_f64Function · 0.70
compare_field_bytesFunction · 0.70
append_field_valueFunction · 0.70
append_field_value_rangeFunction · 0.70
extract_f64_valFunction · 0.70
read_f64_float32Function · 0.70
fuzz_two_byte_patternsFunction · 0.70
extract_numberFunction · 0.50
read_value_as_stringFunction · 0.50

Calls 4

getFunction · 0.85
read_u64_beFunction · 0.85
read_u32_beFunction · 0.85
read_u16_beFunction · 0.85

Tested by 5

read_f64_float32Function · 0.56
fuzz_two_byte_patternsFunction · 0.56