fabric-protos icon indicating copy to clipboard operation
fabric-protos copied to clipboard

[nodebinding] missing FromOject alternative

Open davidkhala opened this issue 3 years ago • 5 comments

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 avatar Jun 18 '22 14:06 davidkhala

In another way, it is a reverse of toObject. Reference to https://github.com/grpc/grpc-node/issues/1730

davidkhala avatar Jun 18 '22 15:06 davidkhala

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 avatar Jun 20 '22 15:06 jt-nti

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

davidkhala avatar Jun 21 '22 16:06 davidkhala

@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.

jt-nti avatar Jun 21 '22 17:06 jt-nti

@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 avatar Jun 22 '22 00:06 davidkhala