8000 Protocol Buffer Basics: Python · Issue #124 · protocolbuffers/protocolbuffers.github.io · GitHub
[go: up one dir, main page]

Skip to content

Protocol Buffer Basics: Python #124

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

Closed
amlitt4 opened this issue Feb 28, 2024 · 4 comments
Closed

Protocol Buffer Basics: Python #124

amlitt4 opened this issue Feb 28, 2024 · 4 comments

Comments

@amlitt4
Copy link
amlitt4 commented Feb 28, 2024

The code snippet referenced in section "The Protocol Buffer API" is no longer accurate. Section should be updated to reflect how latest python code is compiled. meta_class is no longer used.

The previous code snippet:
class Person(message.Message):
metaclass = reflection.GeneratedProtocolMessageType

class PhoneNumber(message.Message):
metaclass = reflection.GeneratedProtocolMessageType
DESCRIPTOR = _PERSON_PHONENUMBER
DESCRIPTOR = _PERSON

class AddressBook(message.Message):
metaclass = reflection.GeneratedProtocolMessageType
DESCRIPTOR = _ADDRESSBOOK

Compiled code using latest repository on 2/28/24:

"""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
_sym_db = _symbol_database.Default()

DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x11\x61\x64\x64ressbook.proto\x12\x08tutorial"\xd9\x02\n\x06Person\x12\x11\n\x04name\x18\x01 \x01(\tH\x00\x88\x01\x01\x12\x0f\n\x02id\x18\x02 \x01(\x05H\x01\x88\x01\x01\x12\x12\n\x05\x65mail\x18\x03 \x01(\tH\x02\x88\x01\x01\x12,\n\x06phones\x18\x04 \x03(\x0b\x32\x1c.tutorial.Person.PhoneNumber\x1a\x65\n\x0bPhoneNumber\x12\x13\n\x06number\x18\x01 \x01(\tH\x00\x88\x01\x01\x12-\n\x04type\x18\x02 \x01(\x0e\x32\x1a.tutorial.Person.PhoneTypeH\x01\x88\x01\x01\x42\t\n\x07_numberB\x07\n\x05_type"h\n\tPhoneType\x12\x1a\n\x16PHONE_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11PHONE_TYPE_MOBILE\x10\x01\x12\x13\n\x0fPHONE_TYPE_HOME\x10\x02\x12\x13\n\x0fPHONE_TYPE_WORK\x10\x03\x42\x07\n\x05_nameB\x05\n\x03_idB\x08\n\x06_email"/\n\x0b\x41\x64\x64ressBook\x12 \n\x06people\x18\x01 \x03(\x0b\x32\x10.tutorial.Personb\x06proto3')

_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'addressbook_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
_globals['_PERSON']._serialized_start=32
_globals['_PERSON']._serialized_end=377
_globals['_PERSON_PHONENUMBER']._serialized_start=144
_globals['_PERSON_PHONENUMBER']._serialized_end=245
_globals['_PERSON_PHONETYPE']._serialized_start=247
_globals['_PERSON_PHONETYPE']._serialized_end=351
_globals['_ADDRESSBOOK']._serialized_start=379
_globals['_ADDRESSBOOK']._serialized_end=426

@Logofile
Copy link
Member

Thanks for the suggested updates! I'm checking with our main Python developer to confirm that I can import these updates.

@Logofile
Copy link
Member

Our main Python developer confirmed that the generated code is different now and metaclass is not used any more. I'll work on incorporating your updates.

@Logofile
Copy link
Member

Still on my radar.

@Logofile
Copy link
Member

I applied these changes; thank you for providing them!

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
0