Function bonsaidb::core::key::encode_composite_field
pub fn encode_composite_field<'k, K, T, Bytes>(
value: &'k T,
bytes: &mut Bytes
) -> Result<(), CompositeKeyError>where
K: Key<'k>,
T: KeyEncoding<K>,
Bytes: Write,
👎Deprecated: use
CompositeKeyEncoder
instead. This function does not properly sort variable length encoded fields. See #240.Expand description
Encodes a value using the Key
trait in such a way that multiple values can
still be ordered at the byte level when chained together.
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());