GRPC - python

python -m pip install grpcio -i https://pypi.douban.com/simple #安装grpc
python -m pip install grpcio-tools -i https://pypi.douban.com/simple #安装grpc tools

 https://www.yuque.com/bobby-zpcyu/fgg66n/dzva8f

syntax = "proto3";

message HelloRequest {
  string name = 1;
}
python -m grpc_tools.protoc --python_out=. --grpc_python_out=. -I. helloworld.proto

 

 

from grpc_test import helloworld_pb2

request = helloworld_pb2.HelloRequest()

request.name = "bobby"
req_str = request.SerializeToString()
print(req_str)

request2 = helloworld_pb2.HelloRequest()

request2.ParseFromString(req_str)
print(request2.name)

 

 

 

from grpc_test import helloworld_pb2

request = helloworld_pb2.HelloRequest()

request.name = "bobby"
req_str = request.SerializeToString()
print(req_str)

import json
req_json = {
    "name":"bobby"
}
print(len(json.dumps(req_json)))
print(len(req_str))

 

posted @ 2022-06-19 10:15  xiondun  阅读(46)  评论(0编辑  收藏  举报