MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / array_from_key

Function array_from_key

nodedb/src/control/array_sync/ack_registry.rs:43–54  ·  view source on GitHub ↗

Parse the array name from the head of a composite key. Returns `None` if the key is malformed.

(key: &[u8])

Source from the content-addressed store, hash-verified

41///
42/// Returns `None` if the key is malformed.
43fn array_from_key(key: &[u8]) -> Option<String> {
44 if key.is_empty() {
45 return None;
46 }
47 let name_len = key[0] as usize;
48 if key.len() < 1 + name_len + 8 {
49 return None;
50 }
51 std::str::from_utf8(&key[1..1 + name_len])
52 .ok()
53 .map(|s| s.to_owned())
54}
55
56/// Parse the replica_id from the tail of a composite key.
57fn replica_id_from_key(key: &[u8]) -> Option<u64> {

Callers 1

load_cacheMethod · 0.85

Calls 3

is_emptyMethod · 0.45
lenMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected