Esempio n. 1
0
def FormatField(type_context, field):
    """Format FieldDescriptorProto as a proto field.

  Args:
    type_context: contextual information for message/enum/field.
    field: FieldDescriptor proto.

  Returns:
    Formatted proto field as a string.
  """
    if protoxform_options.HasHideOption(field.options):
        return ''
    leading_comment, trailing_comment = FormatTypeContextComments(type_context)
    annotations = []
    if field.options.HasExtension(validate_pb2.rules):
        rules = field.options.Extensions[validate_pb2.rules]
        annotations.append('(validate.rules) %s' %
                           FormatValidateFieldRules(rules))
    if field.options.deprecated:
        annotations.append('deprecated = true')
    formatted_annotations = '[ %s]' % ','.join(
        annotations) if annotations else ''
    return '%s%s %s = %d%s;\n%s' % (
        leading_comment, FormatFieldType(type_context, field), field.name,
        field.number, formatted_annotations, trailing_comment)
Esempio n. 2
0
def FormatEnumValue(type_context, value):
  """Format a EnumValueDescriptorProto as a proto enum value.

  Args:
    type_context: contextual information for message/enum/field.
    value: EnumValueDescriptorProto.

  Returns:
    Formatted proto enum value as a string.
  """
  if options.HasHideOption(value.options):
    return ''
  leading_comment, trailing_comment = FormatTypeContextComments(type_context)
  annotations = []
  if value.options.deprecated:
    annotations.append('deprecated = true')
  formatted_annotations = '[ %s]' % ','.join(annotations) if annotations else ''
  return '%s%s = %d%s;\n%s' % (leading_comment, value.name, value.number, formatted_annotations,
                               trailing_comment)