Lines Matching refs:field

117       defined in source code instead of the field number. By default, use the
118 field number order.
121 use_field_number: If True, print field numbers instead of names.
138 def _IsMapEntry(field):
139 return (field.type == descriptor.FieldDescriptor.TYPE_MESSAGE and
140 field.message_type.has_options and
141 field.message_type.GetOptions().map_entry)
153 def PrintField(field, value, out, indent=0, as_utf8=False, as_one_line=False,
155 """Print a single field name/value pair."""
158 printer.PrintField(field, value)
161 def PrintFieldValue(field, value, out, indent=0, as_utf8=False,
165 """Print a single field value (not including name)."""
168 printer.PrintFieldValue(field, value)
192 defined in source code instead of the field number. By default, use the
193 field number order.
197 use_field_number: If True, print field numbers instead of names.
217 for field, value in fields:
218 if _IsMapEntry(field):
225 entry_submsg = field.message_type._concrete_class(
227 self.PrintField(field, entry_submsg)
228 elif field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
230 self.PrintField(field, element)
232 self.PrintField(field, value)
234 def PrintField(self, field, value):
235 """Print a single field name/value pair."""
239 out.write(str(field.number))
241 if field.is_extension:
243 if (field.containing_type.GetOptions().message_set_wire_format and
244 field.type == descriptor.FieldDescriptor.TYPE_MESSAGE and
245 field.label == descriptor.FieldDescriptor.LABEL_OPTIONAL):
246 out.write(field.message_type.full_name)
248 out.write(field.full_name)
250 elif field.type == descriptor.FieldDescriptor.TYPE_GROUP:
252 out.write(field.message_type.name)
254 out.write(field.name)
256 if field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
261 self.PrintFieldValue(field, value)
267 def PrintFieldValue(self, field, value):
268 """Print a single field value (not including name).
273 field: The descriptor of the field to be printed.
274 value: The value of the field.
284 if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
295 elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM:
296 enum_value = field.enum_type.values_by_number.get(value, None)
301 elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING:
307 if field.type == descriptor.FieldDescriptor.TYPE_BYTES:
308 # We need to escape non-UTF8 chars in TYPE_BYTES field.
314 elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_BOOL:
319 elif field.cpp_type in _FLOAT_TYPES and self.float_format is not None:
334 allow_field_number: if True, both field number and field name are allowed.
352 Like Parse(), but allows repeated values for a non-repeated field, and uses
360 allow_field_number: if True, both field number and field name are allowed.
381 allow_field_number: if True, both field number and field name are allowed.
402 allow_field_number: if True, both field number and field name are allowed.
458 """Merges a single protocol message field into a message.
461 tokenizer: A tokenizer to parse the field name and values.
484 field = message.Extensions._FindExtensionByName(name)
486 if not field:
488 field = None
492 elif message_descriptor != field.containing_type:
503 field = message_descriptor.fields_by_number.get(number, None)
504 if not field and message_descriptor.is_extendable:
505 field = message.Extensions._FindExtensionByNumber(number)
507 field = message_descriptor.fields_by_name.get(name, None)
510 # .proto file, which actually matches their type names, not their field
512 if not field:
513 field = message_descriptor.fields_by_name.get(name.lower(), None)
514 if field and field.type != descriptor.FieldDescriptor.TYPE_GROUP:
515 field = None
517 if (field and field.type == descriptor.FieldDescriptor.TYPE_GROUP and
518 field.message_type.name != name):
519 field = None
521 if not field:
523 'Message type "%s" has no field named "%s".' % (
526 if field:
527 if not self._allow_multiple_scalars and field.containing_oneof:
528 # Check if there's a different field set in this oneof.
529 # Note that we ignore the case if the same field was set before, and we
531 which_oneof = message.WhichOneof(field.containing_oneof.name)
532 if which_oneof is not None and which_oneof != field.name:
534 'Field "%s" is specified along with field "%s", another member '
536 field.name, which_oneof, field.containing_oneof.name,
539 if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE:
546 if (field.label == descriptor.FieldDescriptor.LABEL_REPEATED
550 merger(tokenizer, message, field)
555 merger(tokenizer, message, field)
557 else: # Proto field is unknown.
566 def _MergeMessageField(self, tokenizer, message, field):
567 """Merges a single scalar field into a message.
570 tokenizer: A tokenizer to parse the field value.
571 message: The message of which field is a member.
572 field: The descriptor of the field to be merged.
577 is_map_entry = _IsMapEntry(field)
585 if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
586 if field.is_extension:
587 sub_message = message.Extensions[field].add()
590 sub_message = field.message_type._concrete_class()
592 sub_message = getattr(message, field.name).add()
594 if field.is_extension:
595 sub_message = message.Extensions[field]
597 sub_message = getattr(message, field.name)
606 value_cpptype = field.message_type.fields_by_name['value'].cpp_type
608 value = getattr(message, field.name)[sub_message.key]
611 getattr(message, field.name)[sub_message.key] = sub_message.value
613 def _MergeScalarField(self, tokenizer, message, field):
614 """Merges a single scalar field into a message.
617 tokenizer: A tokenizer to parse the field value.
619 field: The descriptor of the field to be merged.
628 if field.type in (descriptor.FieldDescriptor.TYPE_INT32,
632 elif field.type in (descriptor.FieldDescriptor.TYPE_INT64,
636 elif field.type in (descriptor.FieldDescriptor.TYPE_UINT32,
639 elif field.type in (descriptor.FieldDescriptor.TYPE_UINT64,
642 elif field.type in (descriptor.FieldDescriptor.TYPE_FLOAT,
645 elif field.type == descriptor.FieldDescriptor.TYPE_BOOL:
647 elif field.type == descriptor.FieldDescriptor.TYPE_STRING:
649 elif field.type == descriptor.FieldDescriptor.TYPE_BYTES:
651 elif field.type == descriptor.FieldDescriptor.TYPE_ENUM:
652 value = tokenizer.ConsumeEnum(field)
654 raise RuntimeError('Unknown field type %d' % field.type)
656 if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
657 if field.is_extension:
658 message.Extensions[field].append(value)
660 getattr(message, field.name).append(value)
662 if field.is_extension:
663 if not self._allow_multiple_scalars and message.HasExtension(field):
666 (message.DESCRIPTOR.full_name, field.full_name))
668 message.Extensions[field] = value
670 if not self._allow_multiple_scalars and message.HasField(field.name):
673 (message.DESCRIPTOR.full_name, field.name))
675 setattr(message, field.name, value)
679 """Skips over contents (value or message) of a field.
682 tokenizer: A tokenizer to parse the field name and values.
684 # Try to guess the type of this field.
685 # If this field is not a message, there should be a ":" between the
686 # field name and the field value and also the field value should not
688 # If there is no ":" or there is a "{" or "<" after ":", this field has
698 """Skips over a complete field (name and value/message).
701 tokenizer: A tokenizer to parse the field name and values.
721 """Skips over a field message.
724 tokenizer: A tokenizer to parse the field name and values.
740 """Skips over a field value.
743 tokenizer: A tokenizer to parse the field name and values.
746 ParseError: In case an invalid field value is found.
759 raise ParseError('Invalid field value: ' + tokenizer.token)
861 """Consumes protocol message field identifier.
1054 def ConsumeEnum(self, field):
1056 result = ParseEnum(field, self.token)
1186 def ParseEnum(field, value):
1193 field: Enum field descriptor.
1202 enum_descriptor = field.enum_type