Skip to content

Check if property is part of proto schema #526

@subk

Description

@subk

Is there a way to check if a plain object is valid regarding to its protobuf message type ?
If I remember correctly, protobufjs v5 was doing so before encoding a message.

I didnt find a way to do it in protobufjs v6

Eg, given this proto :

syntax = "proto3";
package test;
message Foo {
  string bar = 1;
}
const foo = root.lookup('test.Foo');

// should not throw
const validMessage = foo.create({ bar: 'foobar' });

// should throw an Error as 'xyz' is not a valid field
const invalidMessage = foo.create({ bar: 'foobar', xyz: 123 });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions