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

Method deserialize

atomic-core/src/change/format_v3/reader/mod.rs:162–189  ·  view source on GitHub ↗

Deserialize the payload from postcard format. Convenience wrapper around [`postcard::from_bytes`] that handles the error conversion. Historical July 2026 PROVENANCE payloads are decoded through their original positional layout and converted to the current owned provenance type. # Type Parameters `T` - The target type, which must own its deserialized data. # Errors - `FormatError::Postcard` if

(&self)

Source from the content-addressed store, hash-verified

160 /// let header: ChangeHeader = section.deserialize()?;
161 /// ```
162 pub fn deserialize<T: DeserializeOwned + 'static>(&self) -> FormatResult<T> {
163 match postcard::from_bytes(&self.payload) {
164 Ok(value) => Ok(value),
165 Err(current_error) if self.section_type == SectionType::Header => {
166 if let Ok(header) =
167 super::types::envelope::decode_change_header_only_v2(&self.payload)
168 {
169 let value: Box<dyn Any> = Box::new(header);
170 if let Ok(value) = value.downcast::<T>() {
171 return Ok(*value);
172 }
173 }
174 Err(current_error.into())
175 }
176 Err(current_error) if self.section_type == SectionType::Provenance => {
177 if let Ok(provenance) =
178 super::compatibility::deserialize_july_2026_provenance(&self.payload)
179 {
180 let value: Box<dyn Any> = Box::new(provenance);
181 if let Ok(value) = value.downcast::<T>() {
182 return Ok(*value);
183 }
184 }
185 Err(current_error.into())
186 }
187 Err(error) => Err(error.into()),
188 }
189 }
190
191 /// Returns `true` if this is a hashed section (contributes to content hash).
192 #[inline]