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§
Sourcetype Value
type Value
The value type passed to ExtensionSet::set_extension.
Sourcetype Output
type Output
The return type of ExtensionSet::extension.
Required Methods§
Sourcefn decode(number: u32, fields: &UnknownFields) -> Self::Output
fn decode(number: u32, fields: &UnknownFields) -> Self::Output
Decode this extension’s value from the extendee’s unknown fields.
Sourcefn try_encode(
number: u32,
value: Self::Value,
fields: &mut UnknownFields,
) -> Result<(), EncodeError>
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§
Sourcefn encode(number: u32, value: Self::Value, fields: &mut UnknownFields)
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".