mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.3 KiB
52 lines
2.3 KiB
5 years ago
|
// 语法版本声明,必须放在非注释的第一行
|
||
5 years ago
|
// Syntax version declaration. Must be placed on the first line of non-commentary.
|
||
5 years ago
|
syntax = "proto3";
|
||
|
|
||
|
// 包名定义, Python中使用时可以省略不写(PS:我还要再Go中使用,所以留在这里了)
|
||
5 years ago
|
// Package name definition, which can be omitted in Python. (PS: I'll use it again in Go, so stay here)
|
||
5 years ago
|
package demo;
|
||
|
|
||
|
/*
|
||
|
`message`是用来定义传输的数据的格式的, 等号后面的是字段编号
|
||
|
消息定义中的每个字段都有唯一的编号
|
||
|
总体格式类似于Python中定义一个类或者Golang中定义一个结构体
|
||
|
*/
|
||
|
/*
|
||
|
`message` is used to define the structure of the data to be transmitted, After the equal sign is the field number.
|
||
|
Each field in the message definition has a unique number.
|
||
|
The overall format is similar to defining a class in Python or a structure in Golang.
|
||
|
*/
|
||
|
message Request {
|
||
5 years ago
|
int64 client_id = 1;
|
||
|
string request_data = 2;
|
||
5 years ago
|
}
|
||
|
|
||
|
message Response {
|
||
5 years ago
|
int64 server_id = 1;
|
||
|
string response_data = 2;
|
||
5 years ago
|
}
|
||
|
|
||
|
// service是用来给GRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
|
||
|
// `service` is used to define methods for GRPC services in a fixed format, similar to defining an interface in Golang
|
||
|
service GRPCDemo {
|
||
|
// 简单模式
|
||
5 years ago
|
// unary-unary
|
||
5 years ago
|
rpc SimpleMethod (Request) returns (Response);
|
||
|
|
||
|
// 客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应)
|
||
5 years ago
|
// stream-unary (In a single call, the client can transfer data to the server several times,
|
||
5 years ago
|
// but the server can only return a response once.)
|
||
5 years ago
|
rpc ClientStreamingMethod (stream Request) returns (Response);
|
||
5 years ago
|
|
||
|
// 服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应)
|
||
5 years ago
|
// unary-stream (In a single call, the client can only transmit data to the server at one time,
|
||
5 years ago
|
// but the server can return the response many times.)
|
||
5 years ago
|
rpc ServerStreamingMethod (Request) returns (stream Response);
|
||
5 years ago
|
|
||
|
// 双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据)
|
||
5 years ago
|
// stream-stream (In a single call, both client and server can send and receive data
|
||
5 years ago
|
// to each other multiple times.)
|
||
5 years ago
|
rpc BidirectionalStreamingMethod (stream Request) returns (stream Response);
|
||
5 years ago
|
}
|
||
|
|