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.
The official protobuf project support only Java, C++, and Python. Not Javascript.
JSON is limited to certain python objects, and it cannot serialize every python object. Protobuf supports a wider range of data types when compared to JSON. For example, enumerations and methods are supported by Protobuf and not supported by JSON. JSON supports only a subset of python data types.
Benchmark — strings In one – protobufjs was faster, and in the second — JSON was faster. Looking at the schemas, the immediate suspect was the number of strings. We ran the benchmark with this payload (10,000 strings, of length 10 each).
You can certainly send even a binary payload with an HTTP request, or in an HTTP response. Just write the bytes of the protocol buffer directly into the request/response, and make sure to set the content type to "application/octet-stream". The client, and server, should be able to take care of the rest easily.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With