Skip to main content

ZigZagCodec

Struct ZigZagCodec 

Source
pub struct ZigZagCodec<T, P> { /* private fields */ }
Expand description

Type-level unchecked ZigZag + unsigned LEB128 codec.

Encoding is always canonical; P only affects decoding. Encoding-only callers should conventionally use NonStrict because no decoding policy is applied on that path.

§Type Parameters

  • T: Signed integer value type to decode from ZigZag-encoded LEB128 bytes and encode into ZigZag-encoded LEB128 bytes.
  • P: Required type-level decoding policy implementing Leb128DecodePolicy for the underlying unsigned LEB128 payload. Use crate::Strict to reject non-canonical inputs, or NonStrict to accept non-canonical inputs. This parameter does not affect canonical encoding.

The decoding policy is intentionally required so wire-format callers make the canonicality contract explicit. The underlying unsigned LEB128 payload remains subject to its target integer’s maximum decode width and terminal payload bits, including under NonStrict. See that policy’s documentation for the width limits.

ⓘ
use qubit_codec_binary::ZigZagCodec;

let _ = ZigZagCodec::<i64>::default();

§Examples

use qubit_codec_binary::{
    NonStrict,
    ZigZagCodec,
};

let mut output = [0_u8; ZigZagCodec::<i64, NonStrict>::MAX_ENCODE_UNITS_PER_VALUE];
let written = unsafe {
    ZigZagCodec::<i64, NonStrict>::encode(-42, &mut output, 0)
};
assert_eq!(1, written);

let (decoded, consumed) = unsafe {
    ZigZagCodec::<i64, NonStrict>::decode(&output[..written], 0)
}.expect("canonical ZigZag LEB128 value should decode");
assert_eq!(-42, decoded);
assert_eq!(1, consumed.get());

Implementations§

Source§

impl<P> ZigZagCodec<i8, P>

Source

pub const MIN_UNITS_PER_VALUE: usize = <Self as Codec>::MIN_UNITS_PER_VALUE

Minimum number of bytes that can represent a complete value.

Source

pub const MAX_ENCODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_ENCODE_UNITS_PER_VALUE

Maximum number of bytes emitted when encoding this type.

Source

pub const MAX_DECODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_DECODE_UNITS_PER_VALUE

Maximum number of bytes consumed when decoding this type.

Source

pub unsafe fn decode( input: &[u8], input_index: usize, ) -> Result<(i8, NonZeroUsize), Leb128DecodeError>

Decodes a value from input starting at input_index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • input_index: Start index in input.
§Returns

Returns the decoded value and the non-zero number of consumed bytes.

§Errors

Returns Leb128DecodeError if the underlying LEB128 bytes are incomplete, malformed, or non-canonical under strict policy.

§Safety

The caller must guarantee that input_index is a valid boundary and at least Self::MIN_UNITS_PER_VALUE byte is readable from input_index.

Source

pub unsafe fn encode(value: i8, output: &mut [u8], output_index: usize) -> usize

Encodes value into output starting at output_index without bounds checks.

§Parameters
  • value: Value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that the canonical ZigZag LEB128 byte width of value is writable starting at output_index. Reserving Self::MAX_ENCODE_UNITS_PER_VALUE bytes always satisfies this requirement; for a known value, the exact Codec::encode_len is sufficient.

Source§

impl<P> ZigZagCodec<i16, P>

Source

pub const MIN_UNITS_PER_VALUE: usize = <Self as Codec>::MIN_UNITS_PER_VALUE

Minimum number of bytes that can represent a complete value.

Source

pub const MAX_ENCODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_ENCODE_UNITS_PER_VALUE

Maximum number of bytes emitted when encoding this type.

Source

pub const MAX_DECODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_DECODE_UNITS_PER_VALUE

Maximum number of bytes consumed when decoding this type.

Source

pub unsafe fn decode( input: &[u8], input_index: usize, ) -> Result<(i16, NonZeroUsize), Leb128DecodeError>

Decodes a value from input starting at input_index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • input_index: Start index in input.
§Returns

Returns the decoded value and the non-zero number of consumed bytes.

§Errors

Returns Leb128DecodeError if the underlying LEB128 bytes are incomplete, malformed, or non-canonical under strict policy.

§Safety

The caller must guarantee that input_index is a valid boundary and at least Self::MIN_UNITS_PER_VALUE byte is readable from input_index.

Source

pub unsafe fn encode( value: i16, output: &mut [u8], output_index: usize, ) -> usize

Encodes value into output starting at output_index without bounds checks.

§Parameters
  • value: Value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that the canonical ZigZag LEB128 byte width of value is writable starting at output_index. Reserving Self::MAX_ENCODE_UNITS_PER_VALUE bytes always satisfies this requirement; for a known value, the exact Codec::encode_len is sufficient.

Source§

impl<P> ZigZagCodec<i32, P>

Source

pub const MIN_UNITS_PER_VALUE: usize = <Self as Codec>::MIN_UNITS_PER_VALUE

Minimum number of bytes that can represent a complete value.

Source

pub const MAX_ENCODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_ENCODE_UNITS_PER_VALUE

Maximum number of bytes emitted when encoding this type.

Source

pub const MAX_DECODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_DECODE_UNITS_PER_VALUE

Maximum number of bytes consumed when decoding this type.

Source

pub unsafe fn decode( input: &[u8], input_index: usize, ) -> Result<(i32, NonZeroUsize), Leb128DecodeError>

Decodes a value from input starting at input_index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • input_index: Start index in input.
§Returns

Returns the decoded value and the non-zero number of consumed bytes.

§Errors

Returns Leb128DecodeError if the underlying LEB128 bytes are incomplete, malformed, or non-canonical under strict policy.

§Safety

The caller must guarantee that input_index is a valid boundary and at least Self::MIN_UNITS_PER_VALUE byte is readable from input_index.

Source

pub unsafe fn encode( value: i32, output: &mut [u8], output_index: usize, ) -> usize

Encodes value into output starting at output_index without bounds checks.

§Parameters
  • value: Value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that the canonical ZigZag LEB128 byte width of value is writable starting at output_index. Reserving Self::MAX_ENCODE_UNITS_PER_VALUE bytes always satisfies this requirement; for a known value, the exact Codec::encode_len is sufficient.

Source§

impl<P> ZigZagCodec<i64, P>

Source

pub const MIN_UNITS_PER_VALUE: usize = <Self as Codec>::MIN_UNITS_PER_VALUE

Minimum number of bytes that can represent a complete value.

Source

pub const MAX_ENCODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_ENCODE_UNITS_PER_VALUE

Maximum number of bytes emitted when encoding this type.

Source

pub const MAX_DECODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_DECODE_UNITS_PER_VALUE

Maximum number of bytes consumed when decoding this type.

Source

pub unsafe fn decode( input: &[u8], input_index: usize, ) -> Result<(i64, NonZeroUsize), Leb128DecodeError>

Decodes a value from input starting at input_index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • input_index: Start index in input.
§Returns

Returns the decoded value and the non-zero number of consumed bytes.

§Errors

Returns Leb128DecodeError if the underlying LEB128 bytes are incomplete, malformed, or non-canonical under strict policy.

§Safety

The caller must guarantee that input_index is a valid boundary and at least Self::MIN_UNITS_PER_VALUE byte is readable from input_index.

Source

pub unsafe fn encode( value: i64, output: &mut [u8], output_index: usize, ) -> usize

Encodes value into output starting at output_index without bounds checks.

§Parameters
  • value: Value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that the canonical ZigZag LEB128 byte width of value is writable starting at output_index. Reserving Self::MAX_ENCODE_UNITS_PER_VALUE bytes always satisfies this requirement; for a known value, the exact Codec::encode_len is sufficient.

Source§

impl<P> ZigZagCodec<i128, P>

Source

pub const MIN_UNITS_PER_VALUE: usize = <Self as Codec>::MIN_UNITS_PER_VALUE

Minimum number of bytes that can represent a complete value.

Source

pub const MAX_ENCODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_ENCODE_UNITS_PER_VALUE

Maximum number of bytes emitted when encoding this type.

Source

pub const MAX_DECODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_DECODE_UNITS_PER_VALUE

Maximum number of bytes consumed when decoding this type.

Source

pub unsafe fn decode( input: &[u8], input_index: usize, ) -> Result<(i128, NonZeroUsize), Leb128DecodeError>

Decodes a value from input starting at input_index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • input_index: Start index in input.
§Returns

Returns the decoded value and the non-zero number of consumed bytes.

§Errors

Returns Leb128DecodeError if the underlying LEB128 bytes are incomplete, malformed, or non-canonical under strict policy.

§Safety

The caller must guarantee that input_index is a valid boundary and at least Self::MIN_UNITS_PER_VALUE byte is readable from input_index.

Source

pub unsafe fn encode( value: i128, output: &mut [u8], output_index: usize, ) -> usize

Encodes value into output starting at output_index without bounds checks.

§Parameters
  • value: Value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that the canonical ZigZag LEB128 byte width of value is writable starting at output_index. Reserving Self::MAX_ENCODE_UNITS_PER_VALUE bytes always satisfies this requirement; for a known value, the exact Codec::encode_len is sufficient.

Source§

impl<P> ZigZagCodec<isize, P>

Source

pub const MIN_UNITS_PER_VALUE: usize = <Self as Codec>::MIN_UNITS_PER_VALUE

Minimum number of bytes that can represent a complete value.

Source

pub const MAX_ENCODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_ENCODE_UNITS_PER_VALUE

Maximum number of bytes emitted when encoding this type.

Source

pub const MAX_DECODE_UNITS_PER_VALUE: usize = <Self as Codec>::MAX_DECODE_UNITS_PER_VALUE

Maximum number of bytes consumed when decoding this type.

Source

pub unsafe fn decode( input: &[u8], input_index: usize, ) -> Result<(isize, NonZeroUsize), Leb128DecodeError>

Decodes a value from input starting at input_index without bounds checks.

§Parameters
  • input: Source byte buffer.
  • input_index: Start index in input.
§Returns

Returns the decoded value and the non-zero number of consumed bytes.

§Errors

Returns Leb128DecodeError if the underlying LEB128 bytes are incomplete, malformed, or non-canonical under strict policy.

§Safety

The caller must guarantee that input_index is a valid boundary and at least Self::MIN_UNITS_PER_VALUE byte is readable from input_index.

Source

pub unsafe fn encode( value: isize, output: &mut [u8], output_index: usize, ) -> usize

Encodes value into output starting at output_index without bounds checks.

§Parameters
  • value: Value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of written bytes.

§Safety

The caller must guarantee that the canonical ZigZag LEB128 byte width of value is writable starting at output_index. Reserving Self::MAX_ENCODE_UNITS_PER_VALUE bytes always satisfies this requirement; for a known value, the exact Codec::encode_len is sufficient.

Trait Implementations§

Source§

impl<T: Clone, P: Clone> Clone for ZigZagCodec<T, P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P> Codec for ZigZagCodec<i8, P>

Source§

const MIN_UNITS_PER_VALUE: usize = 1

Minimum bytes readable before decoding can be attempted.

Source§

const MAX_ENCODE_UNITS_PER_VALUE: usize = Leb128Codec<u8, NonStrict>::MAX_ENCODE_UNITS_PER_VALUE

Maximum bytes emitted by canonical ZigZag plus unsigned LEB128 encoding.

Source§

const MAX_DECODE_UNITS_PER_VALUE: usize = Leb128Codec<u8, NonStrict>::MAX_DECODE_UNITS_PER_VALUE

Maximum bytes consumed by decoding this signed integer type.

Source§

type Value = i8

The signed integer represented by this codec.

Source§

type Unit = u8

One byte of the ZigZag LEB128 representation.

Source§

type DecodeError = Leb128DecodeError

Detailed errors for incomplete, malformed, or policy-rejected input.

Source§

type EncodeError = !

Encoding is infallible for every value of this signed integer type.

Source§

fn encode_len(&self, value: &i8) -> usize

Returns the exact width of the canonical unsigned LEB128 encoding of value after ZigZag mapping.

§Parameters
  • value: Signed integer value whose encoded width is queried.
§Returns

Returns a width of at least one byte and no more than Self::MAX_ENCODE_UNITS_PER_VALUE. The decoding policy does not affect this length.

Source§

unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(i8, NonZeroUsize), DecodeFailure<Self::DecodeError>>

Decodes one ZigZag-mapped unsigned LEB128 value and reports its byte consumption.

§Parameters
  • input: Source bytes.
  • input_index: Start index of the encoded value.
§Returns

Returns the signed value and the non-zero number of bytes consumed.

§Errors

Returns DecodeFailure::Incomplete with the detailed error retained as its source and a minimum total byte requirement when a valid prefix needs more input. Returns DecodeFailure::Invalid with the detailed error and consumed-byte count for malformed input or, under crate::Strict, a non-canonical underlying unsigned LEB128 representation. The required count is a lower bound, not a guarantee that decoding will succeed at that length. The consumed count is not a guaranteed protocol-field recovery boundary. Non-strict decoding still enforces the target integer’s maximum width and terminal payload-bit limits.

§Safety

input_index must be a valid boundary and at least Self::MIN_UNITS_PER_VALUE bytes must be readable there.

Source§

unsafe fn encode( &mut self, value: &i8, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>

Encodes one value using canonical ZigZag mapping followed by unsigned LEB128 encoding.

§Parameters
  • value: Signed integer value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of bytes written, equal to Self::encode_len for value.

§Errors

This implementation uses Infallible; every value of the signed integer type can be encoded.

§Safety

The caller must ensure Codec::can_encode_value returned true for value. Starting at output_index, provide either the exact Self::encode_len capacity for value or at least Self::MAX_ENCODE_UNITS_PER_VALUE writable bytes.

Source§

const MAX_ENCODE_RESET_UNITS: usize = 0

The maximum unit count emitted when resetting encode state. Read more
Source§

const MAX_ENCODE_FINISH_UNITS: usize = 0

The maximum unit count emitted when finishing encode state at EOF. Read more
Source§

const MAX_DECODE_RESET_VALUES: usize = 0

The maximum value count emitted when resetting decode state. Read more
Source§

const MAX_DECODE_FINISH_VALUES: usize = 0

The maximum value count emitted when finishing decode state. Read more
Source§

fn can_encode_value(&self, _value: &Self::Value) -> bool

Returns whether value is in this codec’s encodable value domain. Read more
Source§

unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits stream-start output and resets encode-side state. Read more
Source§

unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits EOF trailer output and finishes encode-side state. Read more
Source§

unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Emits stream-start values and resets decode-side state. Read more
Source§

unsafe fn decode_eof( &mut self, input: &[Self::Unit], input_index: usize, ) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>

Decodes one value after the caller has established end of input. Read more
Source§

unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Finishes decode-side EOF state into output. Read more
Source§

impl<P> Codec for ZigZagCodec<i16, P>

Source§

const MIN_UNITS_PER_VALUE: usize = 1

Minimum bytes readable before decoding can be attempted.

Source§

const MAX_ENCODE_UNITS_PER_VALUE: usize = Leb128Codec<u16, NonStrict>::MAX_ENCODE_UNITS_PER_VALUE

Maximum bytes emitted by canonical ZigZag plus unsigned LEB128 encoding.

Source§

const MAX_DECODE_UNITS_PER_VALUE: usize = Leb128Codec<u16, NonStrict>::MAX_DECODE_UNITS_PER_VALUE

Maximum bytes consumed by decoding this signed integer type.

Source§

type Value = i16

The signed integer represented by this codec.

Source§

type Unit = u8

One byte of the ZigZag LEB128 representation.

Source§

type DecodeError = Leb128DecodeError

Detailed errors for incomplete, malformed, or policy-rejected input.

Source§

type EncodeError = !

Encoding is infallible for every value of this signed integer type.

Source§

fn encode_len(&self, value: &i16) -> usize

Returns the exact width of the canonical unsigned LEB128 encoding of value after ZigZag mapping.

§Parameters
  • value: Signed integer value whose encoded width is queried.
§Returns

Returns a width of at least one byte and no more than Self::MAX_ENCODE_UNITS_PER_VALUE. The decoding policy does not affect this length.

Source§

unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(i16, NonZeroUsize), DecodeFailure<Self::DecodeError>>

Decodes one ZigZag-mapped unsigned LEB128 value and reports its byte consumption.

§Parameters
  • input: Source bytes.
  • input_index: Start index of the encoded value.
§Returns

Returns the signed value and the non-zero number of bytes consumed.

§Errors

Returns DecodeFailure::Incomplete with the detailed error retained as its source and a minimum total byte requirement when a valid prefix needs more input. Returns DecodeFailure::Invalid with the detailed error and consumed-byte count for malformed input or, under crate::Strict, a non-canonical underlying unsigned LEB128 representation. The required count is a lower bound, not a guarantee that decoding will succeed at that length. The consumed count is not a guaranteed protocol-field recovery boundary. Non-strict decoding still enforces the target integer’s maximum width and terminal payload-bit limits.

§Safety

input_index must be a valid boundary and at least Self::MIN_UNITS_PER_VALUE bytes must be readable there.

Source§

unsafe fn encode( &mut self, value: &i16, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>

Encodes one value using canonical ZigZag mapping followed by unsigned LEB128 encoding.

§Parameters
  • value: Signed integer value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of bytes written, equal to Self::encode_len for value.

§Errors

This implementation uses Infallible; every value of the signed integer type can be encoded.

§Safety

The caller must ensure Codec::can_encode_value returned true for value. Starting at output_index, provide either the exact Self::encode_len capacity for value or at least Self::MAX_ENCODE_UNITS_PER_VALUE writable bytes.

Source§

const MAX_ENCODE_RESET_UNITS: usize = 0

The maximum unit count emitted when resetting encode state. Read more
Source§

const MAX_ENCODE_FINISH_UNITS: usize = 0

The maximum unit count emitted when finishing encode state at EOF. Read more
Source§

const MAX_DECODE_RESET_VALUES: usize = 0

The maximum value count emitted when resetting decode state. Read more
Source§

const MAX_DECODE_FINISH_VALUES: usize = 0

The maximum value count emitted when finishing decode state. Read more
Source§

fn can_encode_value(&self, _value: &Self::Value) -> bool

Returns whether value is in this codec’s encodable value domain. Read more
Source§

unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits stream-start output and resets encode-side state. Read more
Source§

unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits EOF trailer output and finishes encode-side state. Read more
Source§

unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Emits stream-start values and resets decode-side state. Read more
Source§

unsafe fn decode_eof( &mut self, input: &[Self::Unit], input_index: usize, ) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>

Decodes one value after the caller has established end of input. Read more
Source§

unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Finishes decode-side EOF state into output. Read more
Source§

impl<P> Codec for ZigZagCodec<i32, P>

Source§

const MIN_UNITS_PER_VALUE: usize = 1

Minimum bytes readable before decoding can be attempted.

Source§

const MAX_ENCODE_UNITS_PER_VALUE: usize = Leb128Codec<u32, NonStrict>::MAX_ENCODE_UNITS_PER_VALUE

Maximum bytes emitted by canonical ZigZag plus unsigned LEB128 encoding.

Source§

const MAX_DECODE_UNITS_PER_VALUE: usize = Leb128Codec<u32, NonStrict>::MAX_DECODE_UNITS_PER_VALUE

Maximum bytes consumed by decoding this signed integer type.

Source§

type Value = i32

The signed integer represented by this codec.

Source§

type Unit = u8

One byte of the ZigZag LEB128 representation.

Source§

type DecodeError = Leb128DecodeError

Detailed errors for incomplete, malformed, or policy-rejected input.

Source§

type EncodeError = !

Encoding is infallible for every value of this signed integer type.

Source§

fn encode_len(&self, value: &i32) -> usize

Returns the exact width of the canonical unsigned LEB128 encoding of value after ZigZag mapping.

§Parameters
  • value: Signed integer value whose encoded width is queried.
§Returns

Returns a width of at least one byte and no more than Self::MAX_ENCODE_UNITS_PER_VALUE. The decoding policy does not affect this length.

Source§

unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(i32, NonZeroUsize), DecodeFailure<Self::DecodeError>>

Decodes one ZigZag-mapped unsigned LEB128 value and reports its byte consumption.

§Parameters
  • input: Source bytes.
  • input_index: Start index of the encoded value.
§Returns

Returns the signed value and the non-zero number of bytes consumed.

§Errors

Returns DecodeFailure::Incomplete with the detailed error retained as its source and a minimum total byte requirement when a valid prefix needs more input. Returns DecodeFailure::Invalid with the detailed error and consumed-byte count for malformed input or, under crate::Strict, a non-canonical underlying unsigned LEB128 representation. The required count is a lower bound, not a guarantee that decoding will succeed at that length. The consumed count is not a guaranteed protocol-field recovery boundary. Non-strict decoding still enforces the target integer’s maximum width and terminal payload-bit limits.

§Safety

input_index must be a valid boundary and at least Self::MIN_UNITS_PER_VALUE bytes must be readable there.

Source§

unsafe fn encode( &mut self, value: &i32, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>

Encodes one value using canonical ZigZag mapping followed by unsigned LEB128 encoding.

§Parameters
  • value: Signed integer value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of bytes written, equal to Self::encode_len for value.

§Errors

This implementation uses Infallible; every value of the signed integer type can be encoded.

§Safety

The caller must ensure Codec::can_encode_value returned true for value. Starting at output_index, provide either the exact Self::encode_len capacity for value or at least Self::MAX_ENCODE_UNITS_PER_VALUE writable bytes.

Source§

const MAX_ENCODE_RESET_UNITS: usize = 0

The maximum unit count emitted when resetting encode state. Read more
Source§

const MAX_ENCODE_FINISH_UNITS: usize = 0

The maximum unit count emitted when finishing encode state at EOF. Read more
Source§

const MAX_DECODE_RESET_VALUES: usize = 0

The maximum value count emitted when resetting decode state. Read more
Source§

const MAX_DECODE_FINISH_VALUES: usize = 0

The maximum value count emitted when finishing decode state. Read more
Source§

fn can_encode_value(&self, _value: &Self::Value) -> bool

Returns whether value is in this codec’s encodable value domain. Read more
Source§

unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits stream-start output and resets encode-side state. Read more
Source§

unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits EOF trailer output and finishes encode-side state. Read more
Source§

unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Emits stream-start values and resets decode-side state. Read more
Source§

unsafe fn decode_eof( &mut self, input: &[Self::Unit], input_index: usize, ) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>

Decodes one value after the caller has established end of input. Read more
Source§

unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Finishes decode-side EOF state into output. Read more
Source§

impl<P> Codec for ZigZagCodec<i64, P>

Source§

const MIN_UNITS_PER_VALUE: usize = 1

Minimum bytes readable before decoding can be attempted.

Source§

const MAX_ENCODE_UNITS_PER_VALUE: usize = Leb128Codec<u64, NonStrict>::MAX_ENCODE_UNITS_PER_VALUE

Maximum bytes emitted by canonical ZigZag plus unsigned LEB128 encoding.

Source§

const MAX_DECODE_UNITS_PER_VALUE: usize = Leb128Codec<u64, NonStrict>::MAX_DECODE_UNITS_PER_VALUE

Maximum bytes consumed by decoding this signed integer type.

Source§

type Value = i64

The signed integer represented by this codec.

Source§

type Unit = u8

One byte of the ZigZag LEB128 representation.

Source§

type DecodeError = Leb128DecodeError

Detailed errors for incomplete, malformed, or policy-rejected input.

Source§

type EncodeError = !

Encoding is infallible for every value of this signed integer type.

Source§

fn encode_len(&self, value: &i64) -> usize

Returns the exact width of the canonical unsigned LEB128 encoding of value after ZigZag mapping.

§Parameters
  • value: Signed integer value whose encoded width is queried.
§Returns

Returns a width of at least one byte and no more than Self::MAX_ENCODE_UNITS_PER_VALUE. The decoding policy does not affect this length.

Source§

unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(i64, NonZeroUsize), DecodeFailure<Self::DecodeError>>

Decodes one ZigZag-mapped unsigned LEB128 value and reports its byte consumption.

§Parameters
  • input: Source bytes.
  • input_index: Start index of the encoded value.
§Returns

Returns the signed value and the non-zero number of bytes consumed.

§Errors

Returns DecodeFailure::Incomplete with the detailed error retained as its source and a minimum total byte requirement when a valid prefix needs more input. Returns DecodeFailure::Invalid with the detailed error and consumed-byte count for malformed input or, under crate::Strict, a non-canonical underlying unsigned LEB128 representation. The required count is a lower bound, not a guarantee that decoding will succeed at that length. The consumed count is not a guaranteed protocol-field recovery boundary. Non-strict decoding still enforces the target integer’s maximum width and terminal payload-bit limits.

§Safety

input_index must be a valid boundary and at least Self::MIN_UNITS_PER_VALUE bytes must be readable there.

Source§

unsafe fn encode( &mut self, value: &i64, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>

Encodes one value using canonical ZigZag mapping followed by unsigned LEB128 encoding.

§Parameters
  • value: Signed integer value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of bytes written, equal to Self::encode_len for value.

§Errors

This implementation uses Infallible; every value of the signed integer type can be encoded.

§Safety

The caller must ensure Codec::can_encode_value returned true for value. Starting at output_index, provide either the exact Self::encode_len capacity for value or at least Self::MAX_ENCODE_UNITS_PER_VALUE writable bytes.

Source§

const MAX_ENCODE_RESET_UNITS: usize = 0

The maximum unit count emitted when resetting encode state. Read more
Source§

const MAX_ENCODE_FINISH_UNITS: usize = 0

The maximum unit count emitted when finishing encode state at EOF. Read more
Source§

const MAX_DECODE_RESET_VALUES: usize = 0

The maximum value count emitted when resetting decode state. Read more
Source§

const MAX_DECODE_FINISH_VALUES: usize = 0

The maximum value count emitted when finishing decode state. Read more
Source§

fn can_encode_value(&self, _value: &Self::Value) -> bool

Returns whether value is in this codec’s encodable value domain. Read more
Source§

unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits stream-start output and resets encode-side state. Read more
Source§

unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits EOF trailer output and finishes encode-side state. Read more
Source§

unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Emits stream-start values and resets decode-side state. Read more
Source§

unsafe fn decode_eof( &mut self, input: &[Self::Unit], input_index: usize, ) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>

Decodes one value after the caller has established end of input. Read more
Source§

unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Finishes decode-side EOF state into output. Read more
Source§

impl<P> Codec for ZigZagCodec<i128, P>

Source§

const MIN_UNITS_PER_VALUE: usize = 1

Minimum bytes readable before decoding can be attempted.

Source§

const MAX_ENCODE_UNITS_PER_VALUE: usize = Leb128Codec<u128, NonStrict>::MAX_ENCODE_UNITS_PER_VALUE

Maximum bytes emitted by canonical ZigZag plus unsigned LEB128 encoding.

Source§

const MAX_DECODE_UNITS_PER_VALUE: usize = Leb128Codec<u128, NonStrict>::MAX_DECODE_UNITS_PER_VALUE

Maximum bytes consumed by decoding this signed integer type.

Source§

type Value = i128

The signed integer represented by this codec.

Source§

type Unit = u8

One byte of the ZigZag LEB128 representation.

Source§

type DecodeError = Leb128DecodeError

Detailed errors for incomplete, malformed, or policy-rejected input.

Source§

type EncodeError = !

Encoding is infallible for every value of this signed integer type.

Source§

fn encode_len(&self, value: &i128) -> usize

Returns the exact width of the canonical unsigned LEB128 encoding of value after ZigZag mapping.

§Parameters
  • value: Signed integer value whose encoded width is queried.
§Returns

Returns a width of at least one byte and no more than Self::MAX_ENCODE_UNITS_PER_VALUE. The decoding policy does not affect this length.

Source§

unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(i128, NonZeroUsize), DecodeFailure<Self::DecodeError>>

Decodes one ZigZag-mapped unsigned LEB128 value and reports its byte consumption.

§Parameters
  • input: Source bytes.
  • input_index: Start index of the encoded value.
§Returns

Returns the signed value and the non-zero number of bytes consumed.

§Errors

Returns DecodeFailure::Incomplete with the detailed error retained as its source and a minimum total byte requirement when a valid prefix needs more input. Returns DecodeFailure::Invalid with the detailed error and consumed-byte count for malformed input or, under crate::Strict, a non-canonical underlying unsigned LEB128 representation. The required count is a lower bound, not a guarantee that decoding will succeed at that length. The consumed count is not a guaranteed protocol-field recovery boundary. Non-strict decoding still enforces the target integer’s maximum width and terminal payload-bit limits.

§Safety

input_index must be a valid boundary and at least Self::MIN_UNITS_PER_VALUE bytes must be readable there.

Source§

unsafe fn encode( &mut self, value: &i128, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>

Encodes one value using canonical ZigZag mapping followed by unsigned LEB128 encoding.

§Parameters
  • value: Signed integer value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of bytes written, equal to Self::encode_len for value.

§Errors

This implementation uses Infallible; every value of the signed integer type can be encoded.

§Safety

The caller must ensure Codec::can_encode_value returned true for value. Starting at output_index, provide either the exact Self::encode_len capacity for value or at least Self::MAX_ENCODE_UNITS_PER_VALUE writable bytes.

Source§

const MAX_ENCODE_RESET_UNITS: usize = 0

The maximum unit count emitted when resetting encode state. Read more
Source§

const MAX_ENCODE_FINISH_UNITS: usize = 0

The maximum unit count emitted when finishing encode state at EOF. Read more
Source§

const MAX_DECODE_RESET_VALUES: usize = 0

The maximum value count emitted when resetting decode state. Read more
Source§

const MAX_DECODE_FINISH_VALUES: usize = 0

The maximum value count emitted when finishing decode state. Read more
Source§

fn can_encode_value(&self, _value: &Self::Value) -> bool

Returns whether value is in this codec’s encodable value domain. Read more
Source§

unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits stream-start output and resets encode-side state. Read more
Source§

unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits EOF trailer output and finishes encode-side state. Read more
Source§

unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Emits stream-start values and resets decode-side state. Read more
Source§

unsafe fn decode_eof( &mut self, input: &[Self::Unit], input_index: usize, ) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>

Decodes one value after the caller has established end of input. Read more
Source§

unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Finishes decode-side EOF state into output. Read more
Source§

impl<P> Codec for ZigZagCodec<isize, P>

Source§

const MIN_UNITS_PER_VALUE: usize = 1

Minimum bytes readable before decoding can be attempted.

Source§

const MAX_ENCODE_UNITS_PER_VALUE: usize = Leb128Codec<usize, NonStrict>::MAX_ENCODE_UNITS_PER_VALUE

Maximum bytes emitted by canonical ZigZag plus unsigned LEB128 encoding.

Source§

const MAX_DECODE_UNITS_PER_VALUE: usize = Leb128Codec<usize, NonStrict>::MAX_DECODE_UNITS_PER_VALUE

Maximum bytes consumed by decoding this signed integer type.

Source§

type Value = isize

The signed integer represented by this codec.

Source§

type Unit = u8

One byte of the ZigZag LEB128 representation.

Source§

type DecodeError = Leb128DecodeError

Detailed errors for incomplete, malformed, or policy-rejected input.

Source§

type EncodeError = !

Encoding is infallible for every value of this signed integer type.

Source§

fn encode_len(&self, value: &isize) -> usize

Returns the exact width of the canonical unsigned LEB128 encoding of value after ZigZag mapping.

§Parameters
  • value: Signed integer value whose encoded width is queried.
§Returns

Returns a width of at least one byte and no more than Self::MAX_ENCODE_UNITS_PER_VALUE. The decoding policy does not affect this length.

Source§

unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(isize, NonZeroUsize), DecodeFailure<Self::DecodeError>>

Decodes one ZigZag-mapped unsigned LEB128 value and reports its byte consumption.

§Parameters
  • input: Source bytes.
  • input_index: Start index of the encoded value.
§Returns

Returns the signed value and the non-zero number of bytes consumed.

§Errors

Returns DecodeFailure::Incomplete with the detailed error retained as its source and a minimum total byte requirement when a valid prefix needs more input. Returns DecodeFailure::Invalid with the detailed error and consumed-byte count for malformed input or, under crate::Strict, a non-canonical underlying unsigned LEB128 representation. The required count is a lower bound, not a guarantee that decoding will succeed at that length. The consumed count is not a guaranteed protocol-field recovery boundary. Non-strict decoding still enforces the target integer’s maximum width and terminal payload-bit limits.

§Safety

input_index must be a valid boundary and at least Self::MIN_UNITS_PER_VALUE bytes must be readable there.

Source§

unsafe fn encode( &mut self, value: &isize, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>

Encodes one value using canonical ZigZag mapping followed by unsigned LEB128 encoding.

§Parameters
  • value: Signed integer value to encode.
  • output: Destination byte buffer.
  • output_index: Start index in output.
§Returns

Returns the number of bytes written, equal to Self::encode_len for value.

§Errors

This implementation uses Infallible; every value of the signed integer type can be encoded.

§Safety

The caller must ensure Codec::can_encode_value returned true for value. Starting at output_index, provide either the exact Self::encode_len capacity for value or at least Self::MAX_ENCODE_UNITS_PER_VALUE writable bytes.

Source§

const MAX_ENCODE_RESET_UNITS: usize = 0

The maximum unit count emitted when resetting encode state. Read more
Source§

const MAX_ENCODE_FINISH_UNITS: usize = 0

The maximum unit count emitted when finishing encode state at EOF. Read more
Source§

const MAX_DECODE_RESET_VALUES: usize = 0

The maximum value count emitted when resetting decode state. Read more
Source§

const MAX_DECODE_FINISH_VALUES: usize = 0

The maximum value count emitted when finishing decode state. Read more
Source§

fn can_encode_value(&self, _value: &Self::Value) -> bool

Returns whether value is in this codec’s encodable value domain. Read more
Source§

unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits stream-start output and resets encode-side state. Read more
Source§

unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>

Emits EOF trailer output and finishes encode-side state. Read more
Source§

unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Emits stream-start values and resets decode-side state. Read more
Source§

unsafe fn decode_eof( &mut self, input: &[Self::Unit], input_index: usize, ) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>

Decodes one value after the caller has established end of input. Read more
Source§

unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>

Finishes decode-side EOF state into output. Read more
Source§

impl<T: Copy, P: Copy> Copy for ZigZagCodec<T, P>

Source§

impl<T: Debug, P: Debug> Debug for ZigZagCodec<T, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default, P: Default> Default for ZigZagCodec<T, P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Eq, P: Eq> Eq for ZigZagCodec<T, P>

Source§

impl<T: PartialEq, P: PartialEq> PartialEq for ZigZagCodec<T, P>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq, P: PartialEq> StructuralPartialEq for ZigZagCodec<T, P>

Auto Trait Implementations§

§

impl<T, P> Forget for ZigZagCodec<T, P>

§

impl<T, P> Freeze for ZigZagCodec<T, P>
where PhantomData<fn() -> (T, P)>: Freeze,

§

impl<T, P> Move for ZigZagCodec<T, P>

§

impl<T, P> RefUnwindSafe for ZigZagCodec<T, P>

§

impl<T, P> Send for ZigZagCodec<T, P>
where PhantomData<fn() -> (T, P)>: Send,

§

impl<T, P> Sync for ZigZagCodec<T, P>
where PhantomData<fn() -> (T, P)>: Sync,

§

impl<T, P> Unpin for ZigZagCodec<T, P>
where PhantomData<fn() -> (T, P)>: Unpin,

§

impl<T, P> UnsafeUnpin for ZigZagCodec<T, P>

§

impl<T, P> UnwindSafe for ZigZagCodec<T, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.