Open hochhaus opened 8 years ago
+1
Can someone explain how we would use the new fromObject method? I currently use https://github.com/agreatfool/grpc_tools_node_protoc_ts to generate TypeScript types from proto files. Does the PR from protocolbuffers/protobuf#8488 mean that the typescript generation lib need to be updated as well (simple typing change?).
I created example repository to generate fromObject method https://github.com/wapa5pow/protoc-node . It compiles protoc with fromObject.
I created an npm library to serialize pure javascript objects compatible with the protobuf class. https://www.npmjs.com/package/protobuf-js-from-object
Modifying protoc is too heavy and sometimes hard to apply due to your dependency system. So I add a simple solution to serialize a pure object to protobuf binary.
The serialized binary can be deserialized, and you can also send it via networks. The solution is a bit hacky, but it doesn't take many resources like memory or CPU.
For example:
// Serialize
const buffer = serializeFromObject(pureObj, pb.Burger);
// Deserialize
const burger = pb.Burger.deserializeBinary(buffer);
Make sure that the pure object should have all properties as a key even if the property's value is undefined.
this worked for me: https://gist.github.com/kcarlson/0e69fbce5bff8ca2670af83db346df19
https://www.npmjs.com/package/proto-msg-converter This can be helpful
The comment for jspb.Message.GENERATE_FROM_OBJECT states:
However, no such option is currently implemented in the open sourced version. I see the code which generates output for this option (
GenerateClassFromObject
) but it is invoked 0 times.Can the jspb.generate_from_object option be open sourced?