Protobuf message from JSON in javascript
Asked Answered
B

1

9

In python/C#/C/Go/... generated code it is possible to create a proto message instance from JSON. E.g. in Python where you can just do google.protobuf.json_format.Parse(json, message). I would expect the [JavaScript generated code (here and here) to offer the same, but unfortunately this is not the case.

I am currently sending my JSON in a Struct and receiving the same back. So now I want to upack that Struct and get the message back. But I don't know how.

Ballocks answered 6/7, 2020 at 19:24 Comment(0)
O
1

You actually have a library called protobuf.js and you can try it out with ObjectInformationType.fromObject(JSON.parse(msg)).

It parses the JSON object into protobuf.

Oletaoletha answered 8/7, 2020 at 8:9 Comment(1)
Thanks! Yes, but than I would have to combine both the Google JS library and protobuf.js. Not sure how that would work.Ballocks

© 2022 - 2025 — McMap. All rights reserved.