Decode one axis from `data[pos..]`, advancing `pos` past consumed bytes.
(data: &[u8], pos: &mut usize)
| 123 | |
| 124 | /// Decode one axis from `data[pos..]`, advancing `pos` past consumed bytes. |
| 125 | pub fn decode_coord_axis(data: &[u8], pos: &mut usize) -> ArrayResult<DimDict> { |
| 126 | // Dict entries — tag-dispatched. |
| 127 | if *pos >= data.len() { |
| 128 | return Err(ArrayError::SegmentCorruption { |
| 129 | detail: "coord axis: truncated dict tag".into(), |
| 130 | }); |
| 131 | } |
| 132 | let dict_tag = data[*pos]; |
| 133 | *pos += 1; |
| 134 | |
| 135 | let dict_values: Vec<CoordValue> = |
| 136 | match dict_tag { |
| 137 | DICT_TAG_MSGPACK => { |
| 138 | if *pos + 4 > data.len() { |
| 139 | return Err(ArrayError::SegmentCorruption { |
| 140 | detail: "coord axis: truncated dict count".into(), |
| 141 | }); |
| 142 | } |
| 143 | let dict_count = u32::from_le_bytes( |
| 144 | data[*pos..*pos + 4] |
| 145 | .try_into() |
| 146 | .expect("invariant: preceding bounds check guarantees 4 bytes available"), |
| 147 | ) as usize; |
| 148 | *pos += 4; |
| 149 | check_decoded_size(dict_count, MAX_DICT_CARDINALITY, "coord_delta dict_count")?; |
| 150 | |
| 151 | let mut out: Vec<CoordValue> = Vec::with_capacity(dict_count); |
| 152 | for _ in 0..dict_count { |
| 153 | if *pos + 4 > data.len() { |
| 154 | return Err(ArrayError::SegmentCorruption { |
| 155 | detail: "coord axis: truncated dict entry len".into(), |
| 156 | }); |
| 157 | } |
| 158 | let len = |
| 159 | u32::from_le_bytes(data[*pos..*pos + 4].try_into().expect( |
| 160 | "invariant: preceding bounds check guarantees 4 bytes available", |
| 161 | )) as usize; |
| 162 | *pos += 4; |
| 163 | if *pos + len > data.len() { |
| 164 | return Err(ArrayError::SegmentCorruption { |
| 165 | detail: "coord axis: truncated dict entry bytes".into(), |
| 166 | }); |
| 167 | } |
| 168 | let cv: CoordValue = |
| 169 | zerompk::from_msgpack(&data[*pos..*pos + len]).map_err(|e| { |
| 170 | ArrayError::SegmentCorruption { |
| 171 | detail: format!("coord dict decode: {e}"), |
| 172 | } |
| 173 | })?; |
| 174 | *pos += len; |
| 175 | out.push(cv); |
| 176 | } |
| 177 | out |
| 178 | } |
| 179 | DICT_TAG_INT64_FASTLANES => { |
| 180 | if *pos + 8 > data.len() { |
| 181 | return Err(ArrayError::SegmentCorruption { |
| 182 | detail: "coord axis: truncated int64-dict header".into(), |