Parse the array name from the head of a composite key. Returns `None` if the key is malformed.
(key: &[u8])
| 41 | /// |
| 42 | /// Returns `None` if the key is malformed. |
| 43 | fn 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. |
| 57 | fn replica_id_from_key(key: &[u8]) -> Option<u64> { |
no test coverage detected