All, I'm just now starting to use protobuf by way of the support for grpc in NodeJS with TypeScript. One thing that stands out to me right away is that the syntax for initializing and "hydrating" messages is pretty clunky. Just a basic hello world operations has a lot of "ceremony" in order to initialize data objects and populate values:
sayHello: handleUnaryCall<HelloRequest, HelloReply> = (call, callback) > => { > console.log("Handling call", call) > const {name} = call.request.toObject() > > const reply = new HelloReply() > reply.setMessage(`Hello ${name}`) > > callback(null, reply) > } > It feels to me like the most common cases would simply use object literals, or at the very least esnext compatible setters on the value objects. I found a request for such a feature in the grpc-node project https://github.com/grpc/grpc-node/issues/1378 and it looks like the original poster was directed to inquire about it from the protobuf project. I didn't see a corresponding feature request and before raising one myself I wanted to just ask as a general question. Is there a more user friendly way to do this? The .toObject function doesn't really seem to help since it's only "one way". I'd really love to be able to rewrite the above as this instead: sayHello: handleUnaryCall<HelloRequest, HelloReply> = (call, callback) > => { > console.log("Handling call", call) > const {name} = call.request > > callback(null, { message : `Hello ${name}` }) > } > Not only is it shorter, and more idiomatic, it also has the advantage in TypeScript of checking for exhaustivity (all non-null properties must be set) which isn't really possible with the setter-based solution. Thanks -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/24557d7a-3e87-451a-9720-089603b72d15o%40googlegroups.com.