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// 语法版本声明,必须放在非注释的第一行 16// Syntax version declaration. Must be placed on the first line of non-commentary. 17 18syntax = "proto3"; 19// The document of proto3: https://developers.google.com/protocol-buffers/docs/proto3 20 21// 包名定义, Python中使用时可以省略不写 22// Package name definition, which can be omitted in Python. 23package demo; 24 25/* 26`message`是用来定义传输的数据的格式的, 等号后面的是字段编号 27消息定义中的每个字段都有唯一的编号 28总体格式类似于Python中定义一个类或者Golang中定义一个结构体 29*/ 30/* 31`message` is used to define the structure of the data to be transmitted, after the equal sign 32is the field number. Each field in the message definition has a unique number. 33The overall format is similar to defining a class in Python or a structure in Golang. 34*/ 35message Request { 36 int64 client_id = 1; 37 string request_data = 2; 38} 39 40message Response { 41 int64 server_id = 1; 42 string response_data = 2; 43} 44 45// `service` 是用来给gRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口 46// `service` is used to define methods for gRPC services in a fixed format, similar to defining 47//an interface in Golang 48service GRPCDemo { 49 // 一元模式(在一次调用中, 客户端只能向服务器传输一次请求数据, 服务器也只能返回一次响应) 50 // unary-unary(In a single call, the client can only send request once, and the server can 51 // only respond once.) 52 rpc SimpleMethod (Request) returns (Response); 53 54 // 客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应) 55 // stream-unary (In a single call, the client can transfer data to the server several times, 56 // but the server can only return a response once.) 57 rpc ClientStreamingMethod (stream Request) returns (Response); 58 59 // 服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应) 60 // unary-stream (In a single call, the client can only transmit data to the server at one time, 61 // but the server can return the response many times.) 62 rpc ServerStreamingMethod (Request) returns (stream Response); 63 64 // 双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据) 65 // stream-stream (In a single call, both client and server can send and receive data 66 // to each other multiple times.) 67 rpc BidirectionalStreamingMethod (stream Request) returns (stream Response); 68} 69 70