pbjs
pbjs copied to clipboard
add encoder/decoder map generate
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.