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

Method encode

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

Encode the canonical span payload.

(&self)

Source from the content-addressed store, hash-verified

129
130 /// Encode the canonical span payload.
131 pub fn encode(&self) -> Result<Vec<u8>, SpanPatchError> {
132 if self.version != 1 && self.version != VERSION && self.version != LEGACY_SOURCE_VERSION {
133 return Err(SpanPatchError::UnsupportedVersion(self.version));
134 }
135 let mut bytes = MAGIC.to_vec();
136 if self.version == 1 {
137 if !self.semantic_owners.is_empty() {
138 return Err(SpanPatchError::InvalidEncoding);
139 }
140 let legacy = SpanPatchV1 {
141 version: 1,
142 prior_metadata: self.prior_metadata.clone(),
143 ops: self.ops.clone(),
144 };
145 bytes.extend(
146 postcard::to_allocvec(&legacy).map_err(|_| SpanPatchError::InvalidEncoding)?,
147 );
148 } else {
149 bytes.extend(postcard::to_allocvec(self).map_err(|_| SpanPatchError::InvalidEncoding)?);
150 }
151 Ok(bytes)
152 }
153
154 /// Decode one complete supported span payload.
155 pub fn decode(bytes: &[u8]) -> Result<Self, SpanPatchError> {

Calls 3

extendMethod · 0.80
is_emptyMethod · 0.45
cloneMethod · 0.45