Decode one complete supported span payload.
(bytes: &[u8])
| 155 | |
| 156 | /// Decode one complete supported span payload. |
| 157 | pub fn decode(bytes: &[u8]) -> Result<Self, SpanPatchError> { |
| 158 | let payload = bytes |
| 159 | .strip_prefix(MAGIC) |
| 160 | .ok_or(SpanPatchError::WrongMagic)?; |
| 161 | let version = *payload.first().ok_or(SpanPatchError::InvalidEncoding)?; |
| 162 | if version != 1 && version != VERSION { |
| 163 | return Err(SpanPatchError::UnsupportedVersion(version)); |
| 164 | } |
| 165 | let (patch, remaining) = if version == 1 { |
| 166 | let (legacy, remaining): (SpanPatchV1, _) = |
| 167 | postcard::take_from_bytes(payload).map_err(|_| SpanPatchError::InvalidEncoding)?; |
| 168 | ( |
| 169 | Self { |
| 170 | version: legacy.version, |
| 171 | prior_metadata: legacy.prior_metadata, |
| 172 | ops: legacy.ops, |
| 173 | semantic_owners: Vec::new(), |
| 174 | }, |
| 175 | remaining, |
| 176 | ) |
| 177 | } else { |
| 178 | postcard::take_from_bytes(payload).map_err(|_| SpanPatchError::InvalidEncoding)? |
| 179 | }; |
| 180 | if !remaining.is_empty() { |
| 181 | return Err(SpanPatchError::InvalidEncoding); |
| 182 | } |
| 183 | if patch.version != 1 && patch.version != VERSION { |
| 184 | return Err(SpanPatchError::UnsupportedVersion(patch.version)); |
| 185 | } |
| 186 | Ok(patch) |
| 187 | } |
| 188 | |
| 189 | /// Check local byte bounds. Dependency closure, file ownership, and |
| 190 | /// conflicts must additionally be checked against repository state. |