Trait bonsaidb_core::key::CompositeKeyNullHandler
source · pub trait CompositeKeyNullHandler {
// Required methods
fn handle_nulls(
&self,
field_bytes: &mut Cow<'_, [u8]>
) -> Result<(), CompositeKeyError>;
fn decode_nulls_if_needed<'b, 'e>(
&self,
encoded: ByteSource<'b, 'e>
) -> Result<ByteSource<'b, 'e>, CompositeKeyError>;
}
Expand description
A null-byte handling approach for CompositeKeyEncoder
and
CompositeKeyDecoder
. This type is only used when the fields being
encoded are variable length.
Ensuring proper sort order with composite keys requires special handling of
null bytes. The safest option is to use EscapeNullBytes
, but this option
will cause extra allocations when keys contain null bytes.
AllowNullBytes
allows null-bytes through without any extra checks, but
their usage can cause incorrect sorting behavior. See
CompositeKeyFieldContainsNullByte
for more information on this edge
case. The last implementation is DenyNullBytes
which checks for null
bytes when encoding and returns an error if any are encountered. When
decoding with this option, there is no extra processing performed before
decoding individual fields.
Required Methods§
sourcefn handle_nulls(
&self,
field_bytes: &mut Cow<'_, [u8]>
) -> Result<(), CompositeKeyError>
fn handle_nulls( &self, field_bytes: &mut Cow<'_, [u8]> ) -> Result<(), CompositeKeyError>
Process the null bytes in field_bytes
, if needed.
sourcefn decode_nulls_if_needed<'b, 'e>(
&self,
encoded: ByteSource<'b, 'e>
) -> Result<ByteSource<'b, 'e>, CompositeKeyError>
fn decode_nulls_if_needed<'b, 'e>( &self, encoded: ByteSource<'b, 'e> ) -> Result<ByteSource<'b, 'e>, CompositeKeyError>
Decode the null bytes in encoded
, if needed.