pbjs icon indicating copy to clipboard operation
pbjs copied to clipboard

add encoder/decoder map generate

Open findstr opened this issue 1 year ago • 0 comments

For some reasons, we need to dynamically decode some structures, like the following:

const schema = pbjs.parseSchema(`
  message Demo {
    optional int32 x = 1;
    optional float y = 2;
  }
`).compile();

const buffer = schema.encode("Demo",{x: 1, y: 2});
console.log(buffer);

const message = schema.decode("Demo", buffer);
console.log(message);

So I added two maps, mapping the names of the structures to the encoder and decoder functions.

findstr avatar Jun 12 '24 11:06 findstr