Trait otopr::encoding::Encodable [−][src]
pub trait Encodable {
type Wire: WireType;
fn encoded_size<V: VarInt>(&self, field_number: V) -> usize;
fn encode(&self, s: &mut ProtobufSerializer<impl BufMut>);
fn encode_field<V: VarInt>(
&self,
s: &mut ProtobufSerializer<impl BufMut>,
field_number: V
) { ... }
unsafe fn encode_field_precomputed(
&self,
s: &mut ProtobufSerializer<impl BufMut>,
field_number: &[u8]
) { ... }
}
Associated Types
Required methods
fn encoded_size<V: VarInt>(&self, field_number: V) -> usize
fn encoded_size<V: VarInt>(&self, field_number: V) -> usize
returns the size in bytes when encoded, including the field number.
fn encode(&self, s: &mut ProtobufSerializer<impl BufMut>)
Provided methods
fn encode_field<V: VarInt>(
&self,
s: &mut ProtobufSerializer<impl BufMut>,
field_number: V
)
fn encode_field<V: VarInt>(
&self,
s: &mut ProtobufSerializer<impl BufMut>,
field_number: V
)
The entry point to encoding Encodable
s in a message.
the default implementation writes field_number << 3 | wire_type as an varint and calls [encode()
].
unsafe fn encode_field_precomputed(
&self,
s: &mut ProtobufSerializer<impl BufMut>,
field_number: &[u8]
)
unsafe fn encode_field_precomputed(
&self,
s: &mut ProtobufSerializer<impl BufMut>,
field_number: &[u8]
)
Encodes a field using precomputed bytes for the field number and the wire type varint.
Safety
You must ensure that the bytes are valid varint. That is, all bytes except the last has the MSB set.