fabric-protos
fabric-protos copied to clipboard
[nodebinding] missing FromOject alternative
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.
In another way, it is a reverse of toObject.
Reference to https://github.com/grpc/grpc-node/issues/1730
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.
@jt-nti I believe it is inevitable and sad. We need to selectively pick up protobuf to write builders for own use.
@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 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