Package google :: Package protobuf :: Module descriptor :: Class FieldDescriptor
[hide private]
[frames] | no frames]

Class FieldDescriptor

source code

    object --+    
             |    
DescriptorBase --+
                 |
                FieldDescriptor

Descriptor for a single field in a .proto file.

A FieldDescriptor instance has the following attributes:

  name: (str) Name of this field, exactly as it appears in .proto.
  full_name: (str) Name of this field, including containing scope.  This is
    particularly relevant for extensions.
  camelcase_name: (str) Camelcase name of this field.
  index: (int) Dense, 0-indexed index giving the order that this
    field textually appears within its message in the .proto file.
  number: (int) Tag number declared for this field in the .proto file.

  type: (One of the TYPE_* constants below) Declared type.
  cpp_type: (One of the CPPTYPE_* constants below) C++ type used to
    represent this field.

  label: (One of the LABEL_* constants below) Tells whether this
    field is optional, required, or repeated.
  has_default_value: (bool) True if this field has a default value defined,
    otherwise false.
  default_value: (Varies) Default value of this field.  Only
    meaningful for non-repeated scalar fields.  Repeated fields
    should always set this to [], and non-repeated composite
    fields should always set this to None.

  containing_type: (Descriptor) Descriptor of the protocol message
    type that contains this field.  Set by the Descriptor constructor
    if we're passed into one.
    Somewhat confusingly, for extension fields, this is the
    descriptor of the EXTENDED message, not the descriptor
    of the message containing this field.  (See is_extension and
    extension_scope below).
  message_type: (Descriptor) If a composite field, a descriptor
    of the message type contained in this field.  Otherwise, this is None.
  enum_type: (EnumDescriptor) If this field contains an enum, a
    descriptor of that enum.  Otherwise, this is None.

  is_extension: True iff this describes an extension field.
  extension_scope: (Descriptor) Only meaningful if is_extension is True.
    Gives the message that immediately contains this extension field.
    Will be None iff we're a top-level (file-level) extension field.

  options: (descriptor_pb2.FieldOptions) Protocol message field options or
    None to use default field options.

  containing_oneof: (OneofDescriptor) If the field is a member of a oneof
    union, contains its descriptor. Otherwise, None.

  file: (FileDescriptor) Reference to file descriptor.

Instance Methods [hide private]
a new object with type S, a subtype of T
__new__(cls, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=None, serialized_options=None, has_default_value=True, containing_oneof=None, json_name=None, file=None) source code
 
__init__(self, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=None, serialized_options=None, has_default_value=True, containing_oneof=None, json_name=None, file=None)
The arguments are as described in the description of FieldDescriptor attributes above.
source code

Inherited from DescriptorBase: GetOptions

Inherited from DescriptorBase (private): _SetOptions

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
ProtoTypeToCppProtoType(proto_type)
Converts from a Python proto type to a C++ Proto Type.
source code
Class Variables [hide private]
  TYPE_DOUBLE = 1
  TYPE_FLOAT = 2
  TYPE_INT64 = 3
  TYPE_UINT64 = 4
  TYPE_INT32 = 5
  TYPE_FIXED64 = 6
  TYPE_FIXED32 = 7
  TYPE_BOOL = 8
  TYPE_STRING = 9
  TYPE_GROUP = 10
  TYPE_MESSAGE = 11
  TYPE_BYTES = 12
  TYPE_UINT32 = 13
  TYPE_ENUM = 14
  TYPE_SFIXED32 = 15
  TYPE_SFIXED64 = 16
  TYPE_SINT32 = 17
  TYPE_SINT64 = 18
  MAX_TYPE = 18
  CPPTYPE_INT32 = 1
  CPPTYPE_INT64 = 2
  CPPTYPE_UINT32 = 3
  CPPTYPE_UINT64 = 4
  CPPTYPE_DOUBLE = 5
  CPPTYPE_FLOAT = 6
  CPPTYPE_BOOL = 7
  CPPTYPE_ENUM = 8
  CPPTYPE_STRING = 9
  CPPTYPE_MESSAGE = 10
  MAX_CPPTYPE = 10
  _PYTHON_TO_CPP_PROTO_TYPE_MAP = {1: 5, 2: 6, 3: 2, 4: 4, 5: 1,...
  LABEL_OPTIONAL = 1
  LABEL_REQUIRED = 2
  LABEL_REPEATED = 3
  MAX_LABEL = 3
  MAX_FIELD_NUMBER = 536870911
  FIRST_RESERVED_FIELD_NUMBER = 19000
  LAST_RESERVED_FIELD_NUMBER = 19999
  _C_DESCRIPTOR_CLASS = _message.FieldDescriptor
Properties [hide private]
  camelcase_name

Inherited from object: __class__

Method Details [hide private]

__new__(cls, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=None, serialized_options=None, has_default_value=True, containing_oneof=None, json_name=None, file=None)

source code 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__
(inherited documentation)

__init__(self, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=None, serialized_options=None, has_default_value=True, containing_oneof=None, json_name=None, file=None)
(Constructor)

source code 

The arguments are as described in the description of FieldDescriptor attributes above.

Note that containing_type may be None, and may be set later if necessary (to deal with circular references between message types, for example). Likewise for extension_scope.

Overrides: object.__init__

ProtoTypeToCppProtoType(proto_type)
Static Method

source code 
Converts from a Python proto type to a C++ Proto Type.

The Python ProtocolBuffer classes specify both the 'Python' datatype and the
'C++' datatype - and they're not the same. This helper method should
translate from one to another.

Args:
  proto_type: the Python proto type (descriptor.FieldDescriptor.TYPE_*)
Returns:
  descriptor.FieldDescriptor.CPPTYPE_*, the C++ type.
Raises:
  TypeTransformationError: when the Python proto type isn't known.


Class Variable Details [hide private]

_PYTHON_TO_CPP_PROTO_TYPE_MAP

Value:
{1: 5,
 2: 6,
 3: 2,
 4: 4,
 5: 1,
 6: 4,
 7: 3,
 8: 7,
...

Property Details [hide private]

camelcase_name

Get Method:
unreachable.camelcase_name(self)