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

Function decode_block_range

nodedb-codec/src/fastlanes/mod.rs:130–158  ·  view source on GitHub ↗

Decode a range of blocks [start_block..end_block) from encoded data. More efficient than calling `decode_single_block` repeatedly — scans headers once to find start_block, then decodes contiguously.

(
    data: &[u8],
    start_block: usize,
    end_block: usize,
)

Source from the content-addressed store, hash-verified

128/// More efficient than calling `decode_single_block` repeatedly — scans
129/// headers once to find start_block, then decodes contiguously.
130pub fn decode_block_range(
131 data: &[u8],
132 start_block: usize,
133 end_block: usize,
134) -> Result<Vec<i64>, CodecError> {
135 if data.len() < GLOBAL_HEADER_SIZE {
136 return Err(CodecError::Truncated {
137 expected: GLOBAL_HEADER_SIZE,
138 actual: data.len(),
139 });
140 }
141 let num_blocks = u16::from_le_bytes([data[4], data[5]]) as usize;
142 if start_block >= num_blocks || end_block > num_blocks || start_block >= end_block {
143 return Ok(Vec::new());
144 }
145
146 // Skip to start_block.
147 let mut offset = GLOBAL_HEADER_SIZE;
148 for i in 0..start_block {
149 offset = skip_block(data, offset, i)?;
150 }
151
152 // Decode [start_block..end_block).
153 let mut values = Vec::new();
154 for i in start_block..end_block {
155 offset = decode_block(data, offset, &mut values, i)?;
156 }
157 Ok(values)
158}
159
160/// Number of blocks in an encoded FastLanes stream.
161pub fn block_count(data: &[u8]) -> Result<usize, CodecError> {

Callers

nothing calls this directly

Calls 3

skip_blockFunction · 0.85
decode_blockFunction · 0.70
lenMethod · 0.45

Tested by

no test coverage detected