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

Function encode_trunk_value

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

Encode trunk data as variable-length bytes for storage. # Layout ```text ┌────────────────────────────────────────────────┐ │ Bytes 0-7: inode (u64 LE) │ │ Byte 8: state (TrunkState encoding) │ │ Byte 9: encoding (Encoding byte) │ │ Bytes 10-13: path_len (u32 LE) │ │ Bytes 14..: path (UTF-8 bytes) │ └──────────────────

(data: &SerializedTrunk)

Source from the content-addressed store, hash-verified

723/// assert_eq!(data, decoded);
724/// ```
725pub fn encode_trunk_value(data: &SerializedTrunk) -> Vec<u8> {
726 let path_bytes = data.path.as_bytes();
727 let path_len = path_bytes.len() as u32;
728
729 let mut bytes = Vec::with_capacity(14 + path_bytes.len());
730
731 // Inode (8 bytes)
732 bytes.extend_from_slice(&data.inode.get().to_le_bytes());
733
734 // State (1 byte)
735 bytes.push(encode_trunk_state(data.state));
736
737 // Encoding (1 byte)
738 bytes.push(data.encoding);
739
740 // Path length (4 bytes)
741 bytes.extend_from_slice(&path_len.to_le_bytes());
742
743 // Path bytes
744 bytes.extend_from_slice(path_bytes);
745
746 bytes
747}
748
749/// Decode trunk data from variable-length bytes.
750///

Calls 6

encode_trunk_stateFunction · 0.85
to_le_bytesMethod · 0.80
getMethod · 0.65
as_bytesMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45