Posts

Showing posts with the label protocol-buffers

Store and retrieve interfaces in golang

Store and retrieve interfaces in golang How can we store array of different structs into some file and retrieve it back in the same format without losing its properties(methods it provides). For example: I have data struct A and struct B , both implementing a common interface X {} with some methods. struct A struct B interface X {} One options is to write both save and retrieve method to accept the interface X slice. However the problem is how to unmarshal it back in some generic way which is not tied to my Data struct. i.e., every time I add a new data struct I need not to change my save or retrieve functions to retrieve back the slice of interface X so that its methods can be used independent of data struct. Example where Unmarshaling throws error : Go PlayGround Link with a small Example 3 Answers 3 However the problem is how to unmarshal it back in some generic way which is not tied to my Data...

Protobuf RPC callbacks

Protobuf RPC callbacks Is there any way to do the invoke call from server to the client with Protobuf RPC(while custom call from client to the server, not directly)? I'm meaning, for example, describe service method in *.proto file with callback param? Im using gRPC library. 1 Answer 1 The general way to do server->client messages in gRPC is through "streaming". That is, the client makes a call to the server, and then the server can "stream" back a series of messages to the client before eventually completing the call. See: http://www.grpc.io/docs/guides/concepts.html#server-streaming-rpc Of course, "streaming" is a pretty different pattern from a traditional "callback", but you can often solve the same problems with it. Note that Cap'n Proto RPC -- an alternative to Protobuf and gRPC -- fully supports calls in both directions by virtue of supportin...