Python

The Field Class

The Field class is the base class for all fields defined on messages. This class cannot be extended by developers.

Field is provided by the protorpc.messages module.

  1. Field()
  2. Class Properties
  3. Instance Methods

Constructor

The constructor of the Field class is defined as follows:

class  Field (message_type, number, [required=False | repeated=False], variant=None, default=None)

Initializes an Field instance. Each sub-class of Field must define the following:

VARIANTS
Set of variant types accepted by that field.
DEFAULT_VARIANT
Default variant type if not specified in constructor.

Arguments

number
Number of the field. Must be unique per message class.
required=False
Whether or not this field is required. Mutually exclusive with the repeated argument; do not specify repeated if you use required.
repeated=False
Whether or not this field is repeated. Mutually exclusive with the required argument; do not specify required=True if you also use repeated=True.
variant=None
Provides additional encoding information that is mainly used by protocol buffers. These variants map to the Type values in descriptor.proto. Best practice is to use default values, but you can specify values as 32-bit, 64-bit, unsigned, etc.
default=None
Default value for the field if not found in the underlying request.

Note: Default values are not permitted for repeated fields or message fields.

Raises the following exceptions:

Class Property

The FieldList class has one property:

default()
The default value for the field.

Instance Methods

FieldList instances have the following methods:

validate(value)
Validates a value assigned to a field.

Arguments

value
The value to evaluate.

Raises a ValidationError if the value is not an expected type.

validate_default_element(value)

Validates a value assigned to a default field. Specific to a single element.

Some fields may allow for delayed resolution of default types necessary in the case of circular definition references. In this case, the default value might be a placeholder that is resolved when needed after all the message classes are defined.

Arguments

value
Default value to validate.

Raises a ValidationError if the value is not an expected type.

validate_default(value)

Validates that a field's default value.

Arguments

value
Default value to validate.

Raises a ValidationError if the value is not an expected type.

message_definition()

Gets a message definition that contains this Field definition. Returns a definition for the Message object that contains the Field. Returns None if Field is defined outside of a message class.

Raises a ValidationError if the value is not an expected type.
{"cc_re__cc_re__cc_by_3_0": ["Field. Returns None if Field is defined outside of a message class.</p>\n  \n    <p>Raises a <a href=\"https://cloud.google.com/appengine/docs/python/tools/protorpc/messages/exceptions#ValidationError\">ValidationError</a> if the value is not an expected type.</p>\n    </dd>\n    </dl>\n</dl>\n\n  \n  </div>\n\n  \n        </div>\n        \n<div id=\"gc-content-footer\" class=\"nocontent\">\n\n<div id=\"gc-content-license\">\n\n    \n    \n      <p>Except as otherwise noted, the content of this page is licensed under the <a href=\"http://creativecommons.org/licenses/by/3.0/\">Creative Commons Attribution 3.0 License</a>, and code samples are licensed under the <a href=\"http://www.apache.org/licenses/LICENSE-2.0\">Apache 2.0 License</a>. For details, see our <a href=\"https://cloud.google.com/site-policies\">Site Policies</a>.</p>\n    \n    \n    \n\n\n    \n  <div id=\"site-licenses\" class=\"maia-aux\">\n    <p class=\"java\">\n      Java is a registered trademark of Oracle and/or its affiliates.\n    </p>\n  </div>\n  <script>\n  devsite.ready(function() {\n    if ($('div[itemprop=artic"]}