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§
sourceconst ENTRY: EncoderEntry<T, R> = _
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§
sourcefn write_field(item: T, writer: FieldWriter<'_, '_, R>)
fn write_field(item: T, writer: FieldWriter<'_, '_, R>)
Writes item
as a field.
sourcefn compute_field_size(item: &mut T, sizer: FieldSizer<'_>)
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§
sourcefn packed<'a>() -> Option<&'a dyn PackedEncode<T>>where
T: 'a,
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.
sourcefn wrap_in_sequence() -> bool
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.
sourcefn write_field_in_sequence(item: T, writer: &mut SequenceWriter<'_, '_, R>)
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.
sourcefn compute_field_size_in_sequence(item: &mut T, sizer: &mut SequenceSizer<'_>)
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.