2

I'm trying to implement a Flatbuffer gRPC server and was original confused by the streaming: "server" definition. After much digging and frustration because of the lack of documentation on the topic I did manage to figure out that there are a few streaming types that can be declared:

rpc_service MonsterStorage {
  Store(Monster):Stat (streaming: "none");
  Retrieve(Stat):Monster (streaming: "server", idempotent);
  GetMaxHitPoint(Monster):Stat (streaming: "client");
  GetMinMaxHitPoints(Monster):Stat (streaming: "bidi");
}

Now I'm even more curious. It seems that bidi was the one that I needed, but what do none, server and client mean? What does idempotent do to the stream?

Is this actually documented somewhere and I'm just terrible at searching? lol.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ddibiase
  • 1,412
  • 1
  • 20
  • 44
  • You may want to read the main gRPC documentation for this. – Aardappel Jan 01 '21 at 01:05
  • Why wouldn't the Flatbuffer docs at least link to the source that explains that? There's isn't any documentation outlining how rpc_service itself shoould be structured. – ddibiase Jan 01 '21 at 15:49

1 Answers1

0

gRPC's introduction to the four types of streaming is https://www.grpc.io/docs/languages/cpp/basics/#defining-the-service

Translating that example into flatbuffers yields:

rpc_service RouteGuide {

// A simple RPC where the client sends a request to the server using the stub
// and waits for a response to come back, just like a normal function call.

/// Obtains the feature at a given position.
GetFeature(Point): Feature (streaming: "none");


// A server-side streaming RPC where the client sends a request to the server
// and gets a stream to read a sequence of messages back. The client reads
// from the returned stream until there are no more messages.

/// Obtains the Features available within the given Rectangle.  Results are
/// streamed rather than returned at once (e.g. in a response message with a
/// repeated field), as the rectangle may cover a large area and contain a
/// huge number of features.
ListFeatures(Rectangle): Feature (streaming: "server");


// A client-side streaming RPC where the client writes a sequence of
// messages and sends them to the server, again using a provided stream.
// Once the client has finished writing the messages, it waits for the server to
// read them all and return its response.

/// Accepts a stream of Points on a route being traversed, returning a
/// RouteSummary when traversal is completed.
RecordRoute(Point): RouteSummary (streaming: "client");


// A bidirectional streaming RPC where both sides send a sequence of
// messages using a read-write stream. The two streams operate
// independently, so clients and servers can read and write in whatever order
// they like: for example, the server could wait to receive all the client
// messages before writing its responses, or it could alternately read a
// message then write a message, or some other combination of reads and
// writes. The order of messages in each stream is preserved.

/// Accepts a stream of RouteNotes sent while a route is being traversed,
/// while receiving other RouteNotes (e.g. from other users).
RouteChat(RouteNote): RouteNote (streaming: "bidi");

}
Kietz
  • 1,186
  • 11
  • 19