fix:Update notes, with more standard words

pull/19938/head
kerbalwzy 6 years ago
parent e3f5320ae2
commit d2a224252d
  1. 21
      examples/python/easy_start_demo/README.md
  2. 20
      examples/python/easy_start_demo/demo.proto
  3. 20
      examples/python/easy_start_demo/demo_grpc_pbs/demo_pb2.py
  4. 8
      examples/python/easy_start_demo/demo_grpc_pbs/demo_pb2_grpc.py

@ -1,35 +1,28 @@
## easyDemo for using GRPC in Python
###主要是介绍了在Python中使用GRPC时, 进行数据传输的四种方式。
###This paper mainly introduces four ways of data transmission when GRPC is used in Python.
## Demo for using gRPC in Python
- ####简单模式 (Simple)
在Python中使用gRPC时, 进行数据传输的四种方式。(Four ways of data transmission when gRPC is used in Python.)
- ####简单模式 (unary-unary)
```text
没啥好说的,跟调普通方法没差
There's nothing to say. It's no different from the usual way.
```
- ####客户端流模式 (Request-streaming)
- ####客户端流模式 (stream-unary)
```text
在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应.
In a single call, the client can transfer data to the server several times,
but the server can only return a response once.
```
- ####服务端流模式 (Response-streaming)
- ####服务端流模式 (unary-stream)
```text
在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应
In a single call, the client can only transmit data to the server at one time,
but the server can return the response many times.
```
- ####双向流模式 (Bidirectional Streaming)
- ####双向流模式 (stream-stream)
```text
在一次调用中, 客户端和服务器都可以向对方多次收发数据
In a single call, both client and server can send and receive data
to each other multiple times.
```
----
Author: Zhongying Wang
Email: kerbalwzy@gmail.com
DateTime: 2019-08-13T23:30:00Z
PythonVersion: Python3.6.3

@ -1,9 +1,9 @@
//
// Syntax version declaration, Must be placed on the first line of non-commentary
// Syntax version declaration. Must be placed on the first line of non-commentary.
syntax = "proto3";
// , Python中使用时可以省略不写(PS:Go中使用,)
// Package name definition, which can be omitted in Python (PS: I'll use it again in Go, so stay here)
// Package name definition, which can be omitted in Python. (PS: I'll use it again in Go, so stay here)
package demo;
/*
@ -17,34 +17,34 @@ 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 {
int64 Cid = 1;
string ReqMsg = 2;
int64 client_id = 1;
string request_data = 2;
}
message Response {
int64 Sid = 1;
string RespMsg = 2;
int64 server_id = 1;
string response_data = 2;
}
// 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 {
//
// Simple
// unary-unary
rpc SimpleMethod (Request) returns (Response);
// , ,
// Request-streaming (In a single call, the client can transfer data to the server several times,
// stream-unary (In a single call, the client can transfer data to the server several times,
// but the server can only return a response once.)
rpc ClientStreamingMethod (stream Request) returns (Response);
// , ,
// Response-streaming (In a single call, the client can only transmit data to the server at one time,
// unary-stream (In a single call, the client can only transmit data to the server at one time,
// but the server can return the response many times.)
rpc ServerStreamingMethod (Request) returns (stream Response);
// (, )
// Bidirectional streaming (In a single call, both client and server can send and receive data
// stream-stream (In a single call, both client and server can send and receive data
// to each other multiple times.)
rpc BidirectionalStreamingMethod (stream Request) returns (stream Response);
}

@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
package='demo',
syntax='proto3',
serialized_options=None,
serialized_pb=_b('\n\ndemo.proto\x12\x04\x64\x65mo\"&\n\x07Request\x12\x0b\n\x03\x43id\x18\x01 \x01(\x03\x12\x0e\n\x06ReqMsg\x18\x02 \x01(\t\"(\n\x08Response\x12\x0b\n\x03Sid\x18\x01 \x01(\x03\x12\x0f\n\x07RespMsg\x18\x02 \x01(\t2\xf0\x01\n\x08GRPCDemo\x12-\n\x0cSimpleMethod\x12\r.demo.Request\x1a\x0e.demo.Response\x12\x38\n\x15\x43lientStreamingMethod\x12\r.demo.Request\x1a\x0e.demo.Response(\x01\x12\x38\n\x15ServerStreamingMethod\x12\r.demo.Request\x1a\x0e.demo.Response0\x01\x12\x41\n\x1c\x42idirectionalStreamingMethod\x12\r.demo.Request\x1a\x0e.demo.Response(\x01\x30\x01\x62\x06proto3')
serialized_pb=_b('\n\ndemo.proto\x12\x04\x64\x65mo\"2\n\x07Request\x12\x11\n\tclient_id\x18\x01 \x01(\x03\x12\x14\n\x0crequest_data\x18\x02 \x01(\t\"4\n\x08Response\x12\x11\n\tserver_id\x18\x01 \x01(\x03\x12\x15\n\rresponse_data\x18\x02 \x01(\t2\xf0\x01\n\x08GRPCDemo\x12-\n\x0cSimpleMethod\x12\r.demo.Request\x1a\x0e.demo.Response\x12\x38\n\x15\x43lientStreamingMethod\x12\r.demo.Request\x1a\x0e.demo.Response(\x01\x12\x38\n\x15ServerStreamingMethod\x12\r.demo.Request\x1a\x0e.demo.Response0\x01\x12\x41\n\x1c\x42idirectionalStreamingMethod\x12\r.demo.Request\x1a\x0e.demo.Response(\x01\x30\x01\x62\x06proto3')
)
@ -34,14 +34,14 @@ _REQUEST = _descriptor.Descriptor(
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='Cid', full_name='demo.Request.Cid', index=0,
name='client_id', full_name='demo.Request.client_id', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='ReqMsg', full_name='demo.Request.ReqMsg', index=1,
name='request_data', full_name='demo.Request.request_data', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
@ -60,7 +60,7 @@ _REQUEST = _descriptor.Descriptor(
oneofs=[
],
serialized_start=20,
serialized_end=58,
serialized_end=70,
)
@ -72,14 +72,14 @@ _RESPONSE = _descriptor.Descriptor(
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='Sid', full_name='demo.Response.Sid', index=0,
name='server_id', full_name='demo.Response.server_id', index=0,
number=1, type=3, cpp_type=2, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='RespMsg', full_name='demo.Response.RespMsg', index=1,
name='response_data', full_name='demo.Response.response_data', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
@ -97,8 +97,8 @@ _RESPONSE = _descriptor.Descriptor(
extension_ranges=[],
oneofs=[
],
serialized_start=60,
serialized_end=100,
serialized_start=72,
serialized_end=124,
)
DESCRIPTOR.message_types_by_name['Request'] = _REQUEST
@ -127,8 +127,8 @@ _GRPCDEMO = _descriptor.ServiceDescriptor(
file=DESCRIPTOR,
index=0,
serialized_options=None,
serialized_start=103,
serialized_end=343,
serialized_start=127,
serialized_end=367,
methods=[
_descriptor.MethodDescriptor(
name='SimpleMethod',

@ -44,7 +44,7 @@ class GRPCDemoServicer(object):
def SimpleMethod(self, request, context):
"""简单模式
Simple
unary-unary
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
@ -52,7 +52,7 @@ class GRPCDemoServicer(object):
def ClientStreamingMethod(self, request_iterator, context):
"""客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应)
Request-streaming (In a single call, the client can transfer data to the server several times,
stream-unary (In a single call, the client can transfer data to the server several times,
but the server can only return a response once.)
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -61,7 +61,7 @@ class GRPCDemoServicer(object):
def ServerStreamingMethod(self, request, context):
"""服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应)
Response-streaming (In a single call, the client can only transmit data to the server at one time,
unary-stream (In a single call, the client can only transmit data to the server at one time,
but the server can return the response many times.)
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -70,7 +70,7 @@ class GRPCDemoServicer(object):
def BidirectionalStreamingMethod(self, request_iterator, context):
"""双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据)
Bidirectional streaming (In a single call, both client and server can send and receive data
stream-stream (In a single call, both client and server can send and receive data
to each other multiple times.)
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)

Loading…
Cancel
Save