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

Method decode

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

Decode one complete supported span payload.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected