encode static method
Implementation
static BuBytes encode({
required List<Object?> protoValues,
required ProtoMessageConfig config,
}) {
final bufferFields = config.fields;
if (bufferFields.length != protoValues.length) {
throw BuError(
DefaultErrorType.invalidLength,
"The values and field IDs must have the same length.",
details: {
"fieldIds": bufferFields.length.toString(),
"variables": protoValues.length.toString(),
},
);
}
final encode = protoValues.indexed.map((e) {
final value = e.$2;
if (value == null) return <int>[];
final encode = _encodeField(
value: value,
config: config.fields.elementAt(e.$1),
syntax: config.syntax,
);
return encode ?? <int>[];
});
return BuBytes.concat(encode);
}