Skip to main content

ExtensionCodec

Trait ExtensionCodec 

Source
pub trait ExtensionCodec {
    type Value;
    type Output;

    // Required methods
    fn decode(number: u32, fields: &UnknownFields) -> Self::Output;
    fn try_encode(
        number: u32,
        value: Self::Value,
        fields: &mut UnknownFields,
    ) -> Result<(), EncodeError>;

    // Provided method
    fn encode(number: u32, value: Self::Value, fields: &mut UnknownFields) { ... }
}
Expand description

One impl per proto field type. Value is what users pass to set; Output is what get returns (Option<Value> for singular, Vec<Elem> for repeated).

Required Associated Types§

Source

type Value

The value type passed to ExtensionSet::set_extension.

Source

type Output

The return type of ExtensionSet::extension.

Required Methods§

Source

fn decode(number: u32, fields: &UnknownFields) -> Self::Output

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

Source

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

Encode value into the extendee’s unknown fields.

The caller is responsible for clearing any prior occurrences (see ExtensionSet::set_extension). This is the one required encode method — the fallible signature is required so that a codec whose encode can fail (the message/group codecs, on an over-limit value) cannot accidentally leave the fallible extension path panicking. Infallible codecs (every scalar) simply end with Ok(()).

Records pushed before an Err may remain in fields; ExtensionSet::try_set_extension stages into a scratch set, so the extendee itself is never affected by a failed set. Do not implement this in terms of encode — that provided wrapper calls back here.

§Errors

Returns EncodeError::MessageTooLarge if a message-typed value’s encoded size exceeds the 2 GiB protobuf limit (MAX_MESSAGE_BYTES).

Provided Methods§

Source

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

Panicking wrapper over try_encode.

§Panics

Panics if try_encode fails — i.e. a message-typed value’s encoded size exceeds the 2 GiB protobuf limit.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ExtensionCodec for Bool

Source§

impl ExtensionCodec for BytesCodec

Source§

impl ExtensionCodec for Double

Source§

impl ExtensionCodec for EnumI32

Source§

impl ExtensionCodec for Fixed32

Source§

impl ExtensionCodec for Fixed64

Source§

impl ExtensionCodec for Float

Source§

impl ExtensionCodec for Int32

Source§

impl ExtensionCodec for Int64

Source§

impl ExtensionCodec for Sfixed32

Source§

impl ExtensionCodec for Sfixed64

Source§

impl ExtensionCodec for Sint32

Source§

impl ExtensionCodec for Sint64

Source§

impl ExtensionCodec for StringCodec

Source§

impl ExtensionCodec for Uint32

Source§

impl ExtensionCodec for Uint64

Source§

impl<C: PackableCodec> ExtensionCodec for PackedRepeated<C>

Source§

impl<C: SingularCodec> ExtensionCodec for Repeated<C>

Source§

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

Source§

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