Skip to main content

Module encoding

Module encoding 

Source
Expand description

Shared encoding utilities for key-value serialization.

This module provides common encoding/decoding primitives used by OpenData storage systems.

§Why Encode/Decode Traits Are Not Defined Here

Rust’s orphan rules prevent implementing a trait for a type when both the trait AND the type are defined in external crates. This prevents conflicting implementations across the ecosystem.

For example, if we defined Encode here in common, then timeseries couldn’t implement common::Encode for u32 or SeriesId (which is a type alias for u32) because:

  • Encode would be foreign to timeseries (defined in common)
  • u32 is foreign to both (defined in std)

The rule is: at least one of {trait, type} must be local to the crate doing the implementation.

Therefore, each storage crate (timeseries, vector) defines its own Encode/Decode traits locally, allowing them to implement these traits for primitives and type aliases. The generic functions like encode_array must also be defined locally since they’re bounded by the local traits.

Structs§

EncodingError
Encoding error with a descriptive message.

Functions§

decode_array_count
Decode the count prefix of an array.
decode_optional_utf8
Decode an optional non-empty UTF-8 string.
decode_u64
Decode a u64 value from 8-byte little-endian.
decode_utf8
Decode a UTF-8 string.
encode_array_count
Encode the count prefix of an array.
encode_optional_utf8
Encode an optional non-empty UTF-8 string.
encode_u64
Encode a u64 value as 8-byte little-endian.
encode_utf8
Encode a UTF-8 string.
validate_fixed_element_array_len
Validate that a buffer length is divisible by the element size for fixed-element arrays.