Merge pull request #1940 from murgatroid99/proto-loader_reject_array

proto-loader: Make serializers reject arrays
This commit is contained in:
Michael Lumish 2021-10-18 13:54:43 -07:00 committed by GitHub
commit b8c2b9a652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
};