Skip to main content

GroupCodec

Struct GroupCodec 

Source
pub struct GroupCodec<M>(/* private fields */);
Expand description

Codec for group-encoded message extension fields (proto2 group syntax or editions features.message_encoding = DELIMITED).

The wire data is UnknownFieldData::Group — the inner fields are already parsed into an UnknownFields sub-tree by the group decoder. Decode re-serializes the inner fields to a temporary buffer then merges into M; encode does the reverse via UnknownFields::decode_from_slice.

The round-trip through bytes is correct but not optimal. The alternative (a Message::write_to_unknown_fields() trait method) would be invasive for a rare-in-practice path: group-encoded extensions don’t appear in real custom options.

Singular decode merges all Group records at the field number (same as MessageCodec). Any malformed record aborts and returns None.

Trait Implementations§

Source§

impl<M: Message + Default> ExtensionCodec for GroupCodec<M>

Source§

type Value = M

The value type passed to ExtensionSet::set_extension.
Source§

type Output = Option<M>

The return type of ExtensionSet::extension.
Source§

fn decode(number: u32, fields: &UnknownFields) -> Option<M>

Decode this extension’s value from the extendee’s unknown fields.
Source§

fn try_encode( number: u32, value: M, fields: &mut UnknownFields, ) -> Result<(), EncodeError>

Encode value into the extendee’s unknown fields. Read more
Source§

fn encode(number: u32, value: Self::Value, fields: &mut UnknownFields)

Panicking wrapper over try_encode. Read more
Source§

impl<M: Message + Default> SingularCodec for GroupCodec<M>

Source§

type Value = M

Source§

fn decode_one(data: &UnknownFieldData) -> Option<M>

Decode one value from one unknown-field record’s data. Read more
Source§

fn decode_one_ctx(data: &UnknownFieldData, ctx: DecodeContext<'_>) -> Option<M>

Decode one value under a decode context shared with the other records of the same field. Read more
Source§

fn decode_packed(_bytes: &[u8], _out: &mut Vec<M>)

Decode all values from a packed LengthDelimited payload. Read more
Source§

fn try_encode_one(value: &M) -> Result<UnknownFieldData, EncodeError>

Encode one value as a single unknown-field record. Read more
Source§

fn encode_one(value: &Self::Value) -> UnknownFieldData

Panicking wrapper over try_encode_one. Read more

Auto Trait Implementations§

§

impl<M> Forget for GroupCodec<M>

§

impl<M> Freeze for GroupCodec<M>
where PhantomData<fn() -> M>: Freeze,

§

impl<M> Move for GroupCodec<M>

§

impl<M> RefUnwindSafe for GroupCodec<M>
where PhantomData<fn() -> M>: RefUnwindSafe,

§

impl<M> Send for GroupCodec<M>
where PhantomData<fn() -> M>: Send,

§

impl<M> Sync for GroupCodec<M>
where PhantomData<fn() -> M>: Sync,

§

impl<M> Unpin for GroupCodec<M>
where PhantomData<fn() -> M>: Unpin,

§

impl<M> UnsafeUnpin for GroupCodec<M>
where PhantomData<fn() -> M>: UnsafeUnpin,

§

impl<M> UnwindSafe for GroupCodec<M>
where PhantomData<fn() -> M>: UnwindSafe,

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> 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 = !

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.