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 @   xiondun  阅读(54)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示