Internal change

PiperOrigin-RevId: 485680539
pull/10887/head
Jie Luo 2 years ago committed by Copybara-Service
parent 54cd5869fa
commit 5fc9c37208
  1. 18
      python/google/protobuf/descriptor.py
  2. 13
      python/google/protobuf/internal/python_message.py

@ -641,6 +641,24 @@ class FieldDescriptor(DescriptorBase):
'has_presence is not ready to use because field %s is not'
' linked with message type nor file' % self.full_name)
@property
def is_packed(self):
"""Returns if the field is packed."""
if self.label != FieldDescriptor.LABEL_REPEATED:
return False
field_type = self.type
if (field_type == FieldDescriptor.TYPE_STRING or
field_type == FieldDescriptor.TYPE_GROUP or
field_type == FieldDescriptor.TYPE_MESSAGE or
field_type == FieldDescriptor.TYPE_BYTES):
return False
if self.containing_type.syntax == 'proto2':
return self.has_options and self.GetOptions().packed
else:
return (not self.has_options or
not self.GetOptions().HasField('packed') or
self.GetOptions().packed)
@staticmethod
def ProtoTypeToCppProtoType(proto_type):
"""Converts from a Python proto type to a C++ Proto Type.

@ -283,20 +283,9 @@ def _IsMessageMapField(field):
def _AttachFieldHelpers(cls, field_descriptor):
is_repeated = (field_descriptor.label == _FieldDescriptor.LABEL_REPEATED)
is_packable = (is_repeated and
wire_format.IsTypePackable(field_descriptor.type))
is_proto3 = field_descriptor.containing_type.syntax == 'proto3'
if not is_packable:
is_packed = False
elif field_descriptor.containing_type.syntax == 'proto2':
is_packed = (field_descriptor.has_options and
field_descriptor.GetOptions().packed)
else:
has_packed_false = (field_descriptor.has_options and
field_descriptor.GetOptions().HasField('packed') and
field_descriptor.GetOptions().packed == False)
is_packed = not has_packed_false
is_map_entry = _IsMapField(field_descriptor)
is_packed = field_descriptor.is_packed
if is_map_entry:
field_encoder = encoder.MapEncoder(field_descriptor)

Loading…
Cancel
Save