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