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

Method encode

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

Encode the canonical span payload.

(&self)

Source from the content-addressed store, hash-verified

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

Calls 3

extendMethod · 0.80
is_emptyMethod · 0.45
cloneMethod · 0.45