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)
| 723 | /// assert_eq!(data, decoded); |
| 724 | /// ``` |
| 725 | pub 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 | /// |