Skip to content
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

[nodebinding] missing FromOject alternative #113

Open
davidkhala opened this issue Jun 18, 2022 · 5 comments
Open

[nodebinding] missing FromOject alternative #113

davidkhala opened this issue Jun 18, 2022 · 5 comments

Comments

@davidkhala
Copy link

davidkhala commented Jun 18, 2022

I want a way to transform a javascript object(or json) to a protobuf binary without set attribute mannually to align schema.
We have found a simple way to do so when using fabric-protos, which depended on protobufjs

typeObject.encode(JSObject).finish()

where the typeObject is the type constructor or type itself such as gateway.EvaluateRequest

Now I wonder if we can have similar clean solution now in @hyperledger/fabric-protos.

@davidkhala
Copy link
Author

davidkhala commented Jun 18, 2022

In another way, it is a reverse of toObject.
Reference to grpc/grpc-node#1730

@jt-nti
Copy link
Member

jt-nti commented Jun 20, 2022

From what I can tell other people have asked similar questions, e.g. How to convert object to protobuf data in nodejs, and there is no equivalent to the protobufjs solution. Possibly related, "JSON support for well-known types hasn't been implemented in javascript yet".

For reference, chaincode node PR hyperledger/fabric-chaincode-node#320 converted from a protobufjs based implementation to the new module, which does result in manually setting attributes.

@davidkhala
Copy link
Author

@jt-nti I believe it is inevitable and sad. We need to selectively pick up protobuf to write builders for own use.

@jt-nti
Copy link
Member

jt-nti commented Jun 21, 2022

@davidkhala it's a pity you can't use the new module- the idea was to try and cut down the need for people to have to duplicate the effort of building the proto files themselves.

@davidkhala
Copy link
Author

davidkhala commented Jun 22, 2022

@davidkhala it's a pity you can't use the new module- the idea was to try and cut down the need for people to have to duplicate the effort of building the proto files themselves.

Oh, I might get you confused. I mean I will use the new module, but still I have to suffered from write setter to get protobuf binary from js object, one by one, so selectively I would pick up those classes in module only when in use

@davidkhala davidkhala changed the title [nodebinding] migration encode then finish [nodebinding] missing FromOject alternative Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants