Определения потоковой передачи gRPC с плоским буфером (bidi, сервер, клиент …)

#flatbuffers

#плоские буферы

Вопрос:

Я пытаюсь реализовать сервер gRPC с плоским буфером и изначально был сбит с толку определением streaming: «сервер». После долгих поисков и разочарований из-за отсутствия документации по этой теме мне удалось выяснить, что существует несколько типов потоковой передачи, которые могут быть объявлены:

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

Теперь мне стало еще любопытнее. Похоже, что биди был тем, кто мне был нужен, но что это значит none server и client что значит? Что indempotent делает с потоком?

Действительно ли это где-то задокументировано, и я просто ужасно разбираюсь в поиске? лол.

Комментарии:

1. Возможно, вы захотите прочитать основную документацию gRPC для этого.

2. Почему в документах Flatbuffer нет хотя бы ссылки на источник, объясняющий это? Нет никакой документации, описывающей, как должен быть структурирован сам rpc_service.

Ответ №1:

Введение gRPC в четыре типа потоковой передачи https://www.grpc.io/docs/languages/cpp/basics/#defining-the-service

Перевод этого примера в плоские буферы дает:

 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");

}