Skip to content

pbjs static-module and from (JSON) #588

@mkmik

Description

@mkmik

protobuf.js version: 6.3.1

How can read JSON data with static-module ?

With dynamic modules I can just do:

protobuf.load("src/foo.proto").then(function(root) {
  var Bar = root.lookup("bar");
  return bar.from({baz: {qux: 3}});
});

and it yields Message { baz: Message { qux: 3 } }

However, the code generated with pbjs -t static-module only defines the create method, which doesn't create the right child object types.

This is particularly painful when having things like oneof which depend on functionality defined in the generated type's protototype to guide the encoding (and thus basically encoding an empty message since it cannot determine which field of the oneof to render).

Should we just generate the from method ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions