-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS generator missing jspb.generate_from_object option #96
Comments
Also, the
|
@xfxyjwf Any chance this bug could be addressed prior to the beta 4 release? It is a large issue for certain use cases of the JS implementation. |
+1 |
Adding @haberman as he was able to help with a few other JS issues. Any chance this could be looked into? |
Many of the options we have internally are legacy/deprecated, so we haven't open-sourced them. The ones that we want to keep we will likely want to integrate into Could you say more about how you want to use Also how do you want to use |
Thanks Joshua. All I need is proto3 JSON support (I was not aware of the different Could the proto3 JSON support be open sourced? |
We don't currently have proto3 JSON support implemented for JavaScript (even internally). Inside Google most JavaScript projects use a wire format called JSPB that is specific to JavaScript and encodes protobufs as arrays indexed by field number like For JavaScript we've implemented binary support which works across proto2/proto3 and can interoperate with other implementations. proto3 JSON support would be possible to implement, but we haven't done it yet. |
@haberman Thanks for the additional context. For what it is worth, the JSPB format that you mentioned looks very similar to the Given that proto3 JSON isn't implemented would it be possible to include the |
Indeed -- that is an example of a format that is similar but not the same as JSPB. I didn't realize that had been open-sourced. |
I was under the impression from https://groups.google.com/d/msg/closure-library-discuss/oRZIfaoFGRQ/0FZpl-RIAgAJ that someone is working on grpc support for javascript that may or may not be supported by closure library |
@stanley-cheung do you have any insight on @pcj's question? |
I am not sure about the full context here, but yes we are working on a javascript client library that will use JS protobuf and the Closure library to support making RPC calls from browsers to gRPC backend via a gRPC gateway. It is still early in that project so nothing concrete is released yet. The current estimate is late Q3 the earliest, probably Q4. |
@stanley-cheung Nice. Keep me posted, I may be interested in helping with that. |
Here's my use case. I maintain a library that interoperates with a network that uses protobufs (proto2) extensively. Since I don't want to tie my library's API to a specific protobuf implementation, its methods accept protobufs as plain objects - same goes for events that provide protobufs (more detailed description here). There's also the issue that I don't convert to camelCase, but |
Hello, all, I'm interested in this issue being resolved as well. Answering @haberman on question in https://github.com/google/protobuf/issues/1591#issuecomment-237001956. I see that at least Is there any dangers with this solution? |
What's the status of this? Are there plans to include My use case is same as @alexeykomov's. Also, Alexey's solution just works. See wiktortomczak/protobuf@68ad1c8. |
+1 |
I would also like to make use of I'm happy to raise a PR for this if it will be considered by the grpc maintainers. |
What is the status of this one? We would like to have fromObject exposed as well. |
@haberman any updates? |
having the same requirement as @jonnyreeves...
|
Remaining issues: * https://github.com/google/protobuf/issues/1591 There's no way to unmarshal from JSON.
+1, any updates? |
Lacking this option is is making it hard to support communication with etcd in the browser (see referenced issue) 🙁 |
Any luck get this issue resolved? It's been 4 years since it was raised. |
I don't know what I'm looking at - So we could have this solved with one line of code? |
I've found a way to convert any plain JavaScript object reliably to its Protobuf counterpart for use with any The answer is that So you can serialize your plain object into the protobuf binary format using const ProtoJsMyMessage = root.lookupType('something.MyMessage'); // protobuf.js
const whatTheHeck = { ... }; // plain JS object containing the message properties
const result = MyMessage.deserializeBinary(ProtoJsMyMessage.encode(whatTheHeck).finish()); // MyMessage is grpc-web So I'm using the protobuf binary format as an interface between the two protobuf libraries, so that I can use gRPC as an interface to communicate with my backend. I'm glad that I have finally arrived at a solution that is more "agile" (/s) than just using JSON. Shoot me now. |
That should be looked at. Saying "toObject/fromObject has some issues and we are discussing it internally" really goes against the point of open source. What are the issues? toObject works well. We are ready to help with pull requests but they get ignored. Is the internal discussion 4 years long? |
+1 |
@murgatroid99 @nicolasnoble Can y'all comment on #96 |
As far as I am aware, people have been successfully using code generated by protoc with Node gRPC just fine for a while. This requested feature would absolutely improve usability, but I assume the statement that it is "unusable" is just hyperbole. |
You mean people used to imperative paradigm (I bet they have backend implemented in Java :-) ). Today people practising functional paradigm have no practical means to use this library. From my perspective lack of support for functional style is good enough reason to keep using protobuf.js. |
Add this feature, please , please, please! |
+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. Modifying protoc is too heavy and sometimes hard to apply due to your dependency system. The serialized binary can be deserialized, and you can also send it via networks. 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. |
Adds the fromObject helper to the public API of generated pb classes. This closes a 5-year-old open issue: https://github.com/protocolbuffers/protobuf/issues/1591 by rebasing this 1-year-old open PR: protocolbuffers/protobuf#8488 based on this 4-year-old workaround: https://github.com/protocolbuffers/protobuf/issues/1591#issuecomment-414778829
this worked for me: https://gist.github.com/kcarlson/0e69fbce5bff8ca2670af83db346df19 |
https://www.npmjs.com/package/proto-msg-converter |
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?
The text was updated successfully, but these errors were encountered: