marshal library
Descriptor-driven protobuf message marshaling (encoding).
Encodes a message represented as Map<String, Object?> into protobuf
binary bytes, using a field descriptor list to determine field numbers,
types, and encoding rules.
Each field descriptor is a Map<String, Object?> with:
'name': field name (String)'number': field number (int)'type': protobuf type string, e.g.'TYPE_INT32','TYPE_STRING''label':'LABEL_REPEATED'for repeated fields; absent or other value for singular fields'typeName': forTYPE_MESSAGE/TYPE_ENUM, the fully-qualified message or enum type name (optional for scalar types)'mapEntry': if present andtrue, indicates this message type is a map entry (haskey= 1 andvalue= 2)'keyType': for map fields, the protobuf type of the key'valueType': for map fields, the protobuf type of the value'messageDescriptor': forTYPE_MESSAGEfields, the nested field descriptor list for the submessage
Proto3 rules applied:
- Singular scalar fields with default values (0, false, "", empty list/map) are not serialized.
- Repeated scalar fields use packed encoding by default.
- Map fields are serialized as repeated message fields with key=1, value=2.
References:
Functions
-
encodeGroupField(
List< int> buffer, int fieldNumber, List<int> body) → List<int> -
Encodes a message field using DELIMITED (group) wire format: a START_GROUP
tag (wire type 3), the submessage
body, then a matching END_GROUP tag (wire type 4). This is the editionsmessage_encoding = DELIMITEDrepresentation (and the proto2groupencoding). Unlike length-prefixed (wire type 2) the body is NOT length-prefixed — it is terminated by the END_GROUP tag. -
marshal(
Map< String, Object?> message, List<Map< descriptor) → List<String, Object?> >int> -
Marshals a message (
message) to protobuf binary bytes usingdescriptor. -
marshalField(
List< int> buffer, int fieldNumber, String type, Object? value, {bool repeated = false, bool explicitPresence = false, bool delimited = false, List<Map< ? messageDescriptor}) → List<String, Object?> >int> -
Marshals a single scalar field value and appends it to
buffer. -
marshalMapField(
List< int> buffer, int fieldNumber, Map<Object?, Object?> mapValue, String keyType, String valueType, {List<Map< ? valueDescriptor}) → List<String, Object?> >int> - Marshals a map field as repeated key-value pair messages.
-
marshalRepeated(
List< int> buffer, int fieldNumber, String type, List<Object?> values) → List<int> -
Marshals a repeated scalar field using packed encoding and appends it to
buffer. -
sizeOfMessage(
Map< String, Object?> message, List<Map< descriptor) → intString, Object?> > -
Calculates the encoded byte size of
messagewithout producing output. -
wireTypeForFieldType(
String type) → int -
Returns the wire type for a protobuf field
typestring.