Trait mesh::payload::FieldEncode

source ·
pub trait FieldEncode<T, R>: Sized {
    const ENTRY: EncoderEntry<T, R> = _;

    // Required methods
    fn write_field(item: T, writer: FieldWriter<'_, '_, R>);
    fn compute_field_size(item: &mut T, sizer: FieldSizer<'_>);

    // Provided methods
    fn packed<'a>() -> Option<&'a dyn PackedEncode<T>>
       where T: 'a { ... }
    fn wrap_in_sequence() -> bool { ... }
    fn write_field_in_sequence(item: T, writer: &mut SequenceWriter<'_, '_, R>) { ... }
    fn compute_field_size_in_sequence(
        item: &mut T,
        sizer: &mut SequenceSizer<'_>,
    ) { ... }
}
Expand description

The FieldEncode trait provides a field encoder for type T.

R is the external resource type, which allows encoding objects with non-protobuf resources such as file descriptors. Most implementors of this trait will be generic over all R.

Provided Associated Constants§

source

const ENTRY: EncoderEntry<T, R> = _

The table encoder entry for this type, used in types from table::encode.

This should not be overridden by implementations.

Required Methods§

source

fn write_field(item: T, writer: FieldWriter<'_, '_, R>)

Writes item as a field.

source

fn compute_field_size(item: &mut T, sizer: FieldSizer<'_>)

Computes the size of item as a field.

Encoding will panic if the write_field call writes a different number of bytes than computed by this call.

Takes a mut reference to allow mutating/stabilizing the value so that the subsequence call to write_field acts on the same value as this call.

Provided Methods§

source

fn packed<'a>() -> Option<&'a dyn PackedEncode<T>>
where T: 'a,

Returns the encoder for writing multiple instances of this field in a packed list, or None if there is no packed encoding for this type.

source

fn wrap_in_sequence() -> bool

Returns whether this field should be wrapped in a message when encoded nested in a sequence (such as a repeated field).

This is necessary to avoid ambiguity between the repeated inner and outer values.

source

fn write_field_in_sequence(item: T, writer: &mut SequenceWriter<'_, '_, R>)

Writes this field as part of a sequence, wrapping it in a message if necessary.

source

fn compute_field_size_in_sequence(item: &mut T, sizer: &mut SequenceSizer<'_>)

Computes the size of this field as part of a sequence, including the size of a wrapping message.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, R> FieldEncode<Cow<'a, str>, R> for BorrowedCowField

source§

impl<'a, R> FieldEncode<Cow<'a, str>, R> for OwningCowField

source§

impl<'a, R> FieldEncode<Cow<'a, [u8]>, R> for BorrowedCowField

source§

impl<'a, R> FieldEncode<Cow<'a, [u8]>, R> for OwningCowField

source§

impl<K, V, T, EK, EV, R> FieldEncode<T, R> for MapField<K, V, EK, EV>
where T: IntoIterator<Item = (K, V)>, &'a mut T: for<'a> IntoIterator<Item = (&'a K, &'a mut V)>, EK: for<'a> FieldEncode<&'a K, R>, EV: FieldEncode<V, R>,

source§

impl<R> FieldEncode<u8, R> for ByteField

source§

impl<R> FieldEncode<u128, R> for U128LittleEndianField

source§

impl<T, E, R> FieldEncode<T, R> for TransparentEncoding<E>
where T: Transparent, E: FieldEncode<<T as Transparent>::Inner, R>,

source§

const ENTRY: EncoderEntry<T, R> = _

source§

impl<T, R> FieldEncode<T, R> for PortField
where T: Into<Port>, R: From<Port>,

source§

impl<T, R> FieldEncode<T, R> for BytesField
where T: AsRef<[u8]>,

source§

impl<T, R> FieldEncode<T, R> for Fixed32Field
where T: FixedNumber<Type = u32>,

source§

impl<T, R> FieldEncode<T, R> for Fixed64Field
where T: FixedNumber<Type = u64>,

source§

impl<T, R> FieldEncode<T, R> for IgnoreField
where T: Default,

source§

impl<T, R> FieldEncode<T, R> for ImpossibleField

source§

impl<T, R> FieldEncode<T, R> for SignedVarintField
where T: ToNumber,

source§

impl<T, R> FieldEncode<T, R> for StringField
where T: AsRef<str>,

source§

impl<T, R> FieldEncode<T, R> for VarintField
where T: ToNumber,

source§

impl<T, R> FieldEncode<T, R> for ZeroCopyEncoding
where T: AsBytes,

source§

impl<T, R> FieldEncode<T, R> for OneofEncoder
where T: OneofEncode<R>,

source§

impl<T, R> FieldEncode<T, R> for TableEncoder

source§

const ENTRY: EncoderEntry<T, R> = _

source§

impl<T, R, E> FieldEncode<Option<T>, R> for OptionField<E>
where E: FieldEncode<T, R>,

source§

impl<T, R, E> FieldEncode<Box<T>, R> for BoxEncoding<E>
where E: FieldEncode<T, R>,

source§

impl<T, R, E> FieldEncode<Arc<T>, R> for ArcEncoding<E>
where T: Clone, E: FieldEncode<T, R>,

source§

impl<T, R, E> FieldEncode<Vec<T>, R> for VecField<E>
where E: FieldEncode<T, R>,

source§

impl<T, R, E> FieldEncode<T, R> for MessageEncoding<E>
where E: MessageEncode<T, R>,

source§

impl<T, R, E, const N: usize> FieldEncode<[T; N], R> for ArrayField<E>
where E: FieldEncode<T, R>,

source§

impl<T, U, R> FieldEncode<T, R> for ResourceField<U>
where T: Into<U>, U: Into<R>,