Skip to main content

Encode

Trait Encode 

Source
pub trait Encode {
    const ENCODED_SIZE_HINT: usize = ENCODED_SIZE_DYNAMIC;

    // Required methods
    fn encoded_size(&self) -> usize;
    unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize);
    unsafe fn decode_and_format(
        buffer: *const u8,
        offset: &mut usize,
        output: &mut Vec<u8>,
        format_spec: &str,
    );

    // Provided methods
    unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize) { ... }
    unsafe fn decode_and_format_at_offset(
        buffer: *const u8,
        offset: usize,
        output: &mut Vec<u8>,
        format_spec: &str,
    ) { ... }
}
Expand description

Trait that must be implemented by all types that can be written to the log queue.

Built-in types are implemented by the library; custom types can derive it via #[derive(Encode)].

§Three-layer type path

  • Layer 1 (Fast Primitive): i32/u64/f64/bool, etc. – dedicated number_format
  • Layer 2 (Fast String): &str/String – length-prefixed encoding
  • Layer 3 (General Display): user-defined types – Display fallback

Provided Associated Constants§

Source

const ENCODED_SIZE_HINT: usize = ENCODED_SIZE_DYNAMIC

Compile-time hint for encoded byte width. Dynamic-width types keep the sentinel value.

Required Methods§

Source

fn encoded_size(&self) -> usize

Returns the number of bytes needed to encode this value into the queue.

Source

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Encodes the value at buffer + offset (hot path).

§Safety

buffer + offset must have sufficient space (guaranteed by alloc_message).

Source

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Decodes from buffer + offset and appends the formatted result to output (cold path).

format_spec is a format specifier such as ".4" or "#x"; an empty string means the default format.

§Safety

buffer + offset must point to valid encoded data.

Provided Methods§

Source

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Encodes the value at a fixed byte offset from buffer.

The default implementation forwards to Encode::encode using a local offset variable. Fixed-width types can override this to perform a direct write at a compile-time-known payload position.

§Safety

buffer + offset must have sufficient space for the encoded value.

Source

unsafe fn decode_and_format_at_offset( buffer: *const u8, offset: usize, output: &mut Vec<u8>, format_spec: &str, )

Decodes from buffer + offset and appends the formatted result.

The default implementation forwards to Encode::decode_and_format using a local mutable offset. Fixed-width types can override this to perform a direct read at a compile-time-known payload position.

§Safety

buffer + offset must point to valid encoded data.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Encode for &str

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for bool

Source§

const ENCODED_SIZE_HINT: usize = 1

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for f32

Source§

const ENCODED_SIZE_HINT: usize = 4

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for f64

Source§

const ENCODED_SIZE_HINT: usize = 8

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for i8

Source§

const ENCODED_SIZE_HINT: usize = 1

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for i16

Source§

const ENCODED_SIZE_HINT: usize = 2

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for i32

Source§

const ENCODED_SIZE_HINT: usize

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

unsafe fn decode_and_format_at_offset( buffer: *const u8, offset: usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for i64

Source§

const ENCODED_SIZE_HINT: usize

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

unsafe fn decode_and_format_at_offset( buffer: *const u8, offset: usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for isize

Source§

const ENCODED_SIZE_HINT: usize

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

unsafe fn decode_and_format_at_offset( buffer: *const u8, offset: usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for u8

Source§

const ENCODED_SIZE_HINT: usize = 1

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for u16

Source§

const ENCODED_SIZE_HINT: usize = 2

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for u32

Source§

const ENCODED_SIZE_HINT: usize

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

unsafe fn decode_and_format_at_offset( buffer: *const u8, offset: usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for u64

Source§

const ENCODED_SIZE_HINT: usize

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

unsafe fn decode_and_format_at_offset( buffer: *const u8, offset: usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for usize

Source§

const ENCODED_SIZE_HINT: usize

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn encode_at_offset(&self, buffer: *mut u8, offset: usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

unsafe fn decode_and_format_at_offset( buffer: *const u8, offset: usize, output: &mut Vec<u8>, format_spec: &str, )

Source§

impl Encode for String

Source§

fn encoded_size(&self) -> usize

Source§

unsafe fn encode(&self, buffer: *mut u8, offset: &mut usize)

Source§

unsafe fn decode_and_format( buffer: *const u8, offset: &mut usize, output: &mut Vec<u8>, format_spec: &str, )

Implementors§