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

Function decode_trunk_value

atomic-core/src/crdt/tables.rs:752–775  ·  view source on GitHub ↗

Decode trunk data from variable-length bytes. Returns `None` if the bytes are invalid or too short.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

750///
751/// Returns `None` if the bytes are invalid or too short.
752pub fn decode_trunk_value(bytes: &[u8]) -> Option<SerializedTrunk> {
753 // Minimum size: 8 (inode) + 1 (state) + 1 (encoding) + 4 (path_len) = 14
754 if bytes.len() < 14 {
755 return None;
756 }
757
758 let inode = Inode::new(u64::from_le_bytes(bytes[0..8].try_into().ok()?));
759 let state = decode_trunk_state(bytes[8]);
760 let encoding = bytes[9];
761 let path_len = u32::from_le_bytes(bytes[10..14].try_into().ok()?) as usize;
762
763 if bytes.len() < 14 + path_len {
764 return None;
765 }
766
767 let path = String::from_utf8(bytes[14..14 + path_len].to_vec()).ok()?;
768
769 Some(SerializedTrunk {
770 inode,
771 state,
772 encoding,
773 path,
774 })
775}
776
777// Tests
778

Calls 2

decode_trunk_stateFunction · 0.85
lenMethod · 0.45