proto-loader: Make serializers reject arrays

This commit is contained in:
Michael Lumish 2021-10-15 09:48:42 -07:00
parent 95290ae243
commit 144c41b366
2 changed files with 4 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@grpc/proto-loader",
"version": "0.6.5",
"version": "0.6.6",
"author": "Google Inc.",
"contributors": [
{

View File

@ -212,6 +212,9 @@ function createDeserializer(
function createSerializer(cls: Protobuf.Type): Serialize<object> {
return function serialize(arg: object): Buffer {
if (Array.isArray(arg)) {
throw new Error(`Failed to serialize message: expected object with ${cls.name} structure, got array instead`);
}
const message = cls.fromObject(arg);
return cls.encode(message).finish() as Buffer;
};