Type Definitions (typedefs) are data structures used by BBPB to store metadata about a protobuf message and its fields, including exact types and field names.
Decoding
Typedefs are optional during decoding. If a typedef is not provided or is missing metadata for a field, BBPB performs a best-effort guess of the type based on the field's wire type.
Important: The decoding function returns a typedef containing the types it actually used to decode each field. You must use this returned typedef to re-encode the message successfully. If you provided an initial typedef, the returned version will be a copy that includes type values for any previously unknown fields.
Encoding
Typedefs are required when encoding a message back to protobuf. The encoder uses the typedef to map fields to their correct binary representation. If the message contains a field not present in the typedef, an exception will be raised.
Best Practice: Always use the exact type definition returned by the decoder for encoding. If you need to change a field's type, decode the message again using the modified typedef rather than manually editing the dictionary before encoding.