hhstore / blog

My Tech Blog: about Mojo / Rust / Golang / Python / Kotlin / Flutter / VueJS / Blockchain etc.
https://github.com/hhstore/blog/issues
291 stars 24 forks source link

Serializing Structured Data: Protocol Buffers + gRPC #101

Open hhstore opened 6 years ago

hhstore commented 6 years ago

protobuf:

官方:

ref:

gRPC:

官方:

hhstore commented 6 years ago

python + protobuf:

官方:

# 官方:
pip install protobuf

protoc --version

## 编译:
protoc -I = $ SRC_DIR --python_out = $ DST_DIR $ SRC_DIR / addressbook.proto

protoc --go_out=. *.proto

python + gRPC:

官方:

pip install grpcio
pip install grpcio-tools
pip install googleapis-common-protos

# 编译 bp + grpc:

# gen all:
gen-gpc-pb-all:
    python -m grpc_tools.protoc \
        --proto_path=./backend/protos \
        --python_out=./backend/protos \
        --grpc_python_out=./backend/protos \
        ./backend/protos/*.proto

# gen:
python -m grpc_tools.protoc \
    --proto_path=. \
    --python_out=. \
    --grpc_python_out=. \
    *.proto

示例代码:

sea + grpc:

ref:

hhstore commented 6 years ago

go + protobuf:

protoc --go_out=. *.proto