Function bonsaidb_core::key::decode_composite_field
source · pub fn decode_composite_field<'a, 'k, T: Key<'k>>(
bytes: &'a [u8]
) -> Result<(T, &'a [u8]), CompositeKeyError>
👎Deprecated: use
CompositeKeyDecoder
instead. This function does not properly sort variable length encoded fields. See #240.Expand description
Decodes a value previously encoded using encode_composite_field()
.
The result is a tuple with the first element being the decoded value, and
the second element is the remainig byte slice.
let value1 = String::from("hello");
let value2 = 42_u32;
let mut key_bytes = Vec::new();
encode_composite_field(&value1, &mut key_bytes).unwrap();
encode_composite_field(&value2, &mut key_bytes).unwrap();
let (decoded_string, remaining_bytes) = decode_composite_field::<String>(&key_bytes).unwrap();
assert_eq!(decoded_string, value1);
let (decoded_u32, remaining_bytes) = decode_composite_field::<u32>(&remaining_bytes).unwrap();
assert_eq!(decoded_u32, value2);
assert!(remaining_bytes.is_empty());