fn key_from_full_binary()

in akd/src/node_state.rs [300:319]


    fn key_from_full_binary(bin: &[u8]) -> Result<NodeStateKey, String> {
        if bin.len() < 45 {
            return Err("Not enough bytes to form a proper key".to_string());
        }

        if bin[0] != StorageType::HistoryNodeState as u8 {
            return Err("Not a history node state key".to_string());
        }

        let len_bytes: [u8; 4] = bin[1..=4].try_into().expect("Slice with incorrect length");
        let val_bytes: [u8; 32] = bin[5..=36].try_into().expect("Slice with incorrect length");
        let epoch_bytes: [u8; 8] = bin[37..=44]
            .try_into()
            .expect("Slice with incorrect length");
        let len = u32::from_le_bytes(len_bytes);
        let val = val_bytes;
        let epoch = u64::from_le_bytes(epoch_bytes);

        Ok(NodeStateKey(NodeLabel { len, val }, epoch))
    }