pub struct UnknownFieldsView<'a> { /* private fields */ }Expand description
A borrowed view of unknown fields.
Stores unknown fields as wire records rather than decoded values, enabling
zero-copy round-tripping for borrowable input spans. Borrowed spans may
hold one or more consecutive complete (tag, value) records: adjacent
unknown fields are coalesced into a single span, so a long run of unknown
fields costs one Vec slot rather than one per field. Synthetic records
cover cases where the view decoder must preserve a value that has no
borrowable source span.
Coalescing bounds the view’s memory only — the decode-time
unknown-field allowance is still charged per field (see
push_record).
Implementations§
Source§impl<'a> UnknownFieldsView<'a>
impl<'a> UnknownFieldsView<'a>
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Total byte length of all unknown field data.
Sourcepub fn write_to(&self, buf: &mut impl EncodeSink)
pub fn write_to(&self, buf: &mut impl EncodeSink)
Write all unknown-field bytes in decode order. Each record holds one
or more complete (tag, value) records, so concatenating them
produces a valid encoding.
Sourcepub fn to_owned(&self) -> Result<UnknownFields, DecodeError>
pub fn to_owned(&self) -> Result<UnknownFields, DecodeError>
Convert to an owned UnknownFields by parsing all stored wire records.
Each record holds one or more consecutive (tag + value) records as
they should be re-emitted. Parsing uses
crate::encoding::decode_unknown_field under exactly the budget
push_record and push_varint
charged at decode time — the same field count and group-nesting depth —
so replay cannot exhaust either. Views holding manually pushed spans
(via push_raw) additionally get
DEFAULT_UNKNOWN_FIELD_LIMIT
slots and the full RECURSION_LIMIT, since
those spans were never charged.
A coalesced borrowed span re-materializes one owned UnknownField per
wire record, so this conversion is where a long run of unknown fields
actually allocates.
§Errors
Returns Err if a stored record is malformed or exceeds the replay
budget. Neither can occur when the view was produced by wire decoding
— every borrowed record was parsed off the wire, and the budget equals
what decoding charged — so any such view converts successfully. Only
views holding push_raw spans can fail here.
Trait Implementations§
Source§impl<'a> Clone for UnknownFieldsView<'a>
impl<'a> Clone for UnknownFieldsView<'a>
Source§fn clone(&self) -> UnknownFieldsView<'a>
fn clone(&self) -> UnknownFieldsView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more