demo.proto 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 gRPC authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // 语法版本声明,必须放在非注释的第一行
  15. // Syntax version declaration. Must be placed on the first line of non-commentary.
  16. syntax = "proto3";
  17. // The document of proto3: https://developers.google.com/protocol-buffers/docs/proto3
  18. // 包名定义, Python中使用时可以省略不写
  19. // Package name definition, which can be omitted in Python.
  20. package demo;
  21. /*
  22. `message`是用来定义传输的数据的格式的, 等号后面的是字段编号
  23. 消息定义中的每个字段都有唯一的编号
  24. 总体格式类似于Python中定义一个类或者Golang中定义一个结构体
  25. */
  26. /*
  27. `message` is used to define the structure of the data to be transmitted, after the equal sign
  28. is the field number. Each field in the message definition has a unique number.
  29. The overall format is similar to defining a class in Python or a structure in Golang.
  30. */
  31. message Request {
  32. int64 client_id = 1;
  33. string request_data = 2;
  34. }
  35. message Response {
  36. int64 server_id = 1;
  37. string response_data = 2;
  38. }
  39. // `service` 是用来给gRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
  40. // `service` is used to define methods for gRPC services in a fixed format, similar to defining
  41. //an interface in Golang
  42. service GRPCDemo {
  43. // 一元模式(在一次调用中, 客户端只能向服务器传输一次请求数据, 服务器也只能返回一次响应)
  44. // unary-unary(In a single call, the client can only send request once, and the server can
  45. // only respond once.)
  46. rpc SimpleMethod (Request) returns (Response);
  47. // 客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应)
  48. // stream-unary (In a single call, the client can transfer data to the server several times,
  49. // but the server can only return a response once.)
  50. rpc ClientStreamingMethod (stream Request) returns (Response);
  51. // 服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应)
  52. // unary-stream (In a single call, the client can only transmit data to the server at one time,
  53. // but the server can return the response many times.)
  54. rpc ServerStreamingMethod (Request) returns (stream Response);
  55. // 双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据)
  56. // stream-stream (In a single call, both client and server can send and receive data
  57. // to each other multiple times.)
  58. rpc BidirectionalStreamingMethod (stream Request) returns (stream Response);
  59. }