MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / decode

Method decode

atomic-core/src/change/span_patch.rs:157–187  ·  view source on GitHub ↗

Decode one complete supported span payload.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected