How do I create custom proto types in the NodeJS implementation?

47 views
Skip to first unread message

luc...@getsirena.com

unread,
Sep 14, 2017, 8:56:35 PM9/14/17
to grpc.io
Hi! I'm trying to add support for 2 types that I need: 

- BSON.ObjectId (for MongoDB IDs)
- Unknown object structure

For the first one, I was thinking on just a type that serializes/deserializes the BSON.ObjectId to a string, it it may be sent as a string.

For the second one, as I need to pass objects where I don't know how they're gonna be, I was thinking on serializing them to a JSON string, and then deserialize it in the other side. 

Is any of this possible? 

If so, how do I start? 

Thanks!
Luciano

Ken Payson

unread,
Oct 3, 2017, 7:24:40 PM10/3/17
to grpc.io
If you can serialize these object types to strings, and need to pack them into a protobuf message, you can put them in the protobuf as serialized strings.

Michael Lumish

unread,
Oct 4, 2017, 1:50:53 PM10/4/17
to Ken Payson, grpc.io
You also don't have to use proto at all. All you need is serializers and deserializers to and from the Buffer type. Then you just need to create a map of method names to method definition objects (https://grpc.io/grpc/node/grpc.html#~MethodDefinition), and pass that to grpc.makeGenericClientConstructor or server.addService, depending on whether you need to use it on the client or server.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/908f10ff-999b-4244-91ca-2657bf0180a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages