Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the difference between the protobuf I generated and the demo,and then how can I use the protobuf message's field #600

Closed
Songjiadong opened this issue Sep 15, 2023 · 3 comments

Comments

@Songjiadong
Copy link

This is my question

at first,this is my protobuf file that is same as demo.

syntax = "proto3";

message CustomResponse {
    bool isSuccess = 1;
    int32 code = 2;
    string message = 3;
}

1.Compile Protobuf for Custom Response

python -m grpc_tools.protoc --proto_path=./proto/ --python_out=./proto/    --grpc_python_out=./proto/ ./proto/response.proto
  1. the content of my requeirement.txt is as follows
aiohttp==3.8.5
aiosignal==1.3.1
async-timeout==4.0.3
attrs==23.1.0
bleach==6.0.0
certifi==2023.7.22
charset-normalizer==3.2.0
cloudevents==1.9.0
colorama==0.4.6
dapr==1.10.0
dapr-ext-grpc==1.10.0
deprecation==2.1.0
docutils==0.20.1
environs==9.5.0
filelock==3.12.3
frozenlist==1.4.0
fsspec==2023.9.0
grpcio==1.56.0
grpcio-tools==1.56.0
huggingface-hub==0.16.4
idna==3.4
importlib-metadata==6.8.0
jaraco.classes==3.3.0
Jinja2==3.1.2
keyring==24.2.0
markdown-it-py==3.0.0
MarkupSafe==2.1.3
marshmallow==3.20.1
mdurl==0.1.2
more-itertools==10.1.0
mpmath==1.3.0
multidict==6.0.4
networkx==3.1
numpy==1.25.2
packaging==23.1
pandas==2.1.0
Pillow==10.0.0
pkginfo==1.9.6
protobuf==4.21.12
pydantic==1.10.12
Pygments==2.16.1
pymilvus==2.3.0
python-dateutil==2.8.2
python-dotenv==1.0.0
pytz==2023.3.post1
pywin32-ctypes==0.2.2
PyYAML==6.0.1
readme-renderer==41.0
regex==2023.8.8
requests==2.31.0
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==13.5.2
safetensors==0.3.3
sentencepiece==0.1.99
six==1.16.0
sympy==1.12
tabulate==0.9.0
tenacity==8.2.3
tokenizers==0.13.3
torch==2.0.1
torchaudio==2.0.2
torchvision==0.15.2
towhee==1.1.1
towhee.models==1.1.1
tqdm==4.66.1
transformers==4.33.1
twine==4.0.2
typing_extensions==4.7.1
tzdata==2023.3
ujson==5.8.0
urllib3==2.0.4
webencodings==0.5.1
yarl==1.9.2
zipp==3.16.2

and this is pb2 file that is my protobuf generate.this file is different from demo,for example my file has not the content of from google.protobuf import message as _message from google.protobuf import reflection as _reflection so how can I use the message data of getter or setter? Help me ,Thank u!

# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: response.proto
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()




DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0eresponse.proto\"B\n\x0e\x43ustomResponse\x12\x11\n\tisSuccess\x18\x01 \x01(\x08\x12\x0c\n\x04\x63ode\x18\x02 \x01(\x05\x12\x0f\n\x07message\x18\x03 \x01(\tb\x06proto3')

_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'response_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:

  DESCRIPTOR._options = None
  _globals['_CUSTOMRESPONSE']._serialized_start=18
  _globals['_CUSTOMRESPONSE']._serialized_end=84
# @@protoc_insertion_point(module_scope)

@berndverst
Copy link
Member

Not sure which demo you are referring to, but maybe take a look at the examples/grpc_proxying sample instead.

@berndverst
Copy link
Member

The example https://github.com/dapr/python-sdk/tree/master/examples/grpc_proxying should have everything you need. Please adjust your code accordingly to match the name of your proto request and response classes.

@Songjiadong
Copy link
Author

Not sure which demo you are referring to, but maybe take a look at the examples/grpc_proxying sample instead.

Yes, I was referring to the demo you mentioned examples/grpc_proxying. and I found

The example https://github.com/dapr/python-sdk/tree/master/examples/grpc_proxying should have everything you need. Please adjust your code accordingly to match the name of your proto request and response classes.

The proto generated by your code is significantly different from the proto generated by my code.And Your code generation seems to be more accurate than me,so I want to know how your proto was generated. Is it related to the version of protobuf? Although I can still solve it through this method req.ParseFromString(request.data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants