FieldEncoding

Struct FieldEncoding 

Source
pub struct FieldEncoding(/* private fields */);
Expand description

Values for the encoding byte of a field definition.

The low 5 bits of the encoding byte contain the field’s encoding. The encoding indicates the following information about the field:

  • How the decoder should determine the size of the field. For example, Value32 indicates a 4-byte field, Value128 indicates a 16-byte field, ZStringChar8 indicates that the field ends at the first char8 unit with value 0, and BinaryLength16Char8 indicates that the first 16 bits of the field are the uint16 Length and that the subsequent Length char8 units of the field are the field data.

  • How the field should be formatted if the field’s format is Default (0), unrecognized, or unsupported. For example, a Value32 encoding with Default or unrecognized format should be treated as if it had UnsignedInt format. A StringLength16Char8 encoding with Default or unrecognized format should be treated as if it had StringUtf format. A BinaryLength16Char8 encoding with Default or unrecognized format should be treated as if it had HexBytes format.

The StringLength16Char8 and BinaryLength16Char8 encodings are special. These encodings can be used with both variable-length (e.g. HexBytes and String) formats as well as with fixed-length (e.g. UnsignedInt, Float, IPAddress) formats. When used with fixed-length formats, the semantics depend on the field’s variable Length (as determined from the first 16 bits of the field):

  • If the Length is 0, the field is formatted as null. For example, a field with encoding = BinaryLength16Char8, format = SignedInt, and Length = 0 would be formatted as a null value.

  • If the Length is appropriate for the format, the field is formatted as if it had the Value8, Value16, Value32, Value64, or Value128 encoding corresponding to its size. For example, a field with encoding = BinaryLength16Char8, format = SignedInt, and Length = 4 would be formatted as an int32 field.

  • If the Length is not appropriate for the format, the field is formatted as if it had the default format for the encoding. For example, a field with encoding = BinaryLength16Char8, format = SignedInt, and Length = 16 would be formatted as a HexBytes field since 16 is not a supported size for the SignedInt format and the default format for BinaryLength16Char8 is HexBytes.

The top 3 bits of the field encoding byte are flags:

  • CArrayFlag indicates that this field is a constant-length array, with the element count specified as a 16-bit value in the event metadata (must not be 0).

  • VArrayFlag indicates that this field is a variable-length array, with the element count specified as a 16-bit value in the event payload (immediately before the array elements, may be 0).

  • ChainFlag indicates that a format byte is present after the encoding byte. If ChainFlag is not set, the format byte is omitted and is assumed to be 0.

Setting both CArrayFlag and VArrayFlag is invalid (reserved).

Implementations§

Source§

impl FieldEncoding

Source

pub const Invalid: FieldEncoding

Invalid encoding value.

Source

pub const Struct: FieldEncoding

0-byte value, logically groups subsequent N fields, N = format & 0x7F, N must not be 0.

Source

pub const Value8: FieldEncoding

1-byte value, default format UnsignedInt.

Usable formats: UnsignedInt, SignedInt, HexInt, Boolean, HexBytes, String8.

Source

pub const Value16: FieldEncoding

2-byte value, default format UnsignedInt.

Usable formats: UnsignedInt, SignedInt, HexInt, Boolean, HexBytes, StringUtf, Port.

Source

pub const Value32: FieldEncoding

4-byte value, default format UnsignedInt.

Usable formats: UnsignedInt, SignedInt, HexInt, Errno, Pid, Time, Boolean, Float, HexBytes, StringUtf, IPv4.

Source

pub const Value64: FieldEncoding

8-byte value, default format UnsignedInt.

Usable formats: UnsignedInt, SignedInt, HexInt, Time, Float, HexBytes.

Source

pub const Value128: FieldEncoding

16-byte value, default format HexBytes.

Usable formats: HexBytes, Uuid, IPv6.

Source

pub const ZStringChar8: FieldEncoding

zero-terminated uint8[], default format StringUtf.

Usable formats: HexBytes, String8, StringUtf, StringUtfBom, StringXml, StringJson.

Source

pub const ZStringChar16: FieldEncoding

zero-terminated uint16[], default format StringUtf.

Usable formats: HexBytes, StringUtf, StringUtfBom, StringXml, StringJson.

Source

pub const ZStringChar32: FieldEncoding

zero-terminated uint32[], default format StringUtf.

Usable formats: HexBytes, StringUtf, StringUtfBom, StringXml, StringJson.

Source

pub const StringLength16Char8: FieldEncoding

uint16 Length followed by uint8 Data[Length], default format StringUtf. Used for string and binary data. Also used for nullable fields.

Usable formats: any.

Source

pub const StringLength16Char16: FieldEncoding

uint16 Length followed by uint16 Data[Length], default format StringUtf.

Usable formats: HexBytes, StringUtf, StringUtfBom, StringXml, StringJson.

Source

pub const StringLength16Char32: FieldEncoding

uint16 Length followed by uint32 Data[Length], default format StringUtf.

Usable formats: HexBytes, StringUtf, StringUtfBom, StringXml, StringJson.

Source

pub const BinaryLength16Char8: FieldEncoding

uint16 Length followed by uint8 Data[Length], default format HexBytes. Used for string and binary data. Also used for nullable fields.

Usable formats: any.

Source

pub const ValueSize: FieldEncoding

usize value, default format UnsignedInt. This is an alias for either Value32 or Value64.

Usable formats: UnsignedInt, SignedInt, HexInt, Time, Float, HexBytes.

Source

pub const ValueMask: u8 = 31u8

Mask for the kind field.

Source

pub const FlagMask: u8 = 224u8

Mask for the flags.

Source

pub const ArrayFlagMask: u8 = 96u8

Mask for the array flags.

Source

pub const CArrayFlag: u8 = 32u8

Constant-length array: 16-bit element count in metadata (count must not be 0).

Source

pub const VArrayFlag: u8 = 64u8

Variable-length array: 16-bit element count in payload (count may be 0).

Source

pub const ChainFlag: u8 = 128u8

A FieldFormat byte follows the FieldEncoding byte.

Source

pub const fn from_int(value: u8) -> FieldEncoding

Returns a FieldEncoding with the specified value.

Source

pub const fn as_int(self) -> u8

Returns the numeric value corresponding to this FieldEncoding value.

Source

pub const fn without_flags(self) -> FieldEncoding

Returns the encoding without any flags (encoding & ValueMask).

Source

pub const fn with_flags(self, flags: u8) -> FieldEncoding

Returns the encoding or’ed with the specified flags (encoding | flags).

Source

pub const fn without_chain_flag(self) -> FieldEncoding

Returns the encoding without the chain flags (encoding & !ChainFlag).

Source

pub const fn array_flags(self) -> u8

Returns the array flags of the encoding (encoding & (CArrayFlag | VArrayFlag)).

Source

pub const fn is_array(self) -> bool

Returns true if any array flag is present (constant-length or variable-length array).

Source

pub const fn is_constant_length_array(self) -> bool

Returns true if CArrayFlag is present (constant-length array).

Source

pub const fn is_variable_length_array(self) -> bool

Returns true if VArrayFlag is present (variable-length array).

Source

pub const fn has_chain_flag(self) -> bool

Returns true if ChainFlag is present (format byte is present in event).

Trait Implementations§

Source§

impl Clone for FieldEncoding

Source§

fn clone(&self) -> FieldEncoding

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldEncoding

Source§

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

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

impl Default for FieldEncoding

Source§

fn default() -> FieldEncoding

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

impl Display for FieldEncoding

Source§

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

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

impl From<u8> for FieldEncoding

Source§

fn from(val: u8) -> FieldEncoding

Converts to this type from the input type.
Source§

impl Hash for FieldEncoding

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for FieldEncoding

Source§

fn cmp(&self, other: &FieldEncoding) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for FieldEncoding

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for FieldEncoding

Source§

fn partial_cmp(&self, other: &FieldEncoding) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for FieldEncoding

Source§

impl Eq for FieldEncoding

Source§

impl StructuralPartialEq for FieldEncoding

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.