pub struct Tag { /* private fields */ }Expand description
A parsed field tag (field number + wire type).
Implementations§
Source§impl Tag
impl Tag
Sourcepub fn new(field_number: u32, wire_type: WireType) -> Self
pub fn new(field_number: u32, wire_type: WireType) -> Self
Create a new tag.
Generated write_to code calls this once per set field with a
constant field number; #[inline] lets the range assert const-fold
away and the tag collapse into the caller, instead of an out-of-line
call per field write in non-LTO builds.
§Panics
Panics if field_number is not in the valid range
[1, MAX_FIELD_NUMBER]. This is a programming error (generated
code always uses valid field numbers); the panic fires in all
build profiles.
Sourcepub fn field_number(&self) -> u32
pub fn field_number(&self) -> u32
Returns the field number carried by this tag.
Sourcepub fn encode(&self, buf: &mut impl EncodeSink)
pub fn encode(&self, buf: &mut impl EncodeSink)
Encode a tag to a buffer.
Sourcepub fn decode(buf: &mut impl Buf) -> Result<Self, DecodeError>
pub fn decode(buf: &mut impl Buf) -> Result<Self, DecodeError>
Decode a tag from a buffer.
Single-byte tags (field numbers 1–15, any wire type) are validated
straight from the first byte, without the Result<u64, _> that
decode_varint returns. A longer tag continues in
decode_varint_multibyte, so the one-byte check is not repeated.