Python 2.7 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Python.
The MessageField Class
Stay organized with collections
Save and categorize content based on your preferences.
The MessageField class is used to define messages for efficient transmission
across network or process space. Messages are defined using
field
classes.
MessageField
is provided by the protorpc.messages
module.
Constructor
The constructor of the MessageField class is defined as follows:
-
class MessageField(message_type,
number,
[required=False | repeated=False])
-
Defines fields for sub-message values.
Arguments
- message_type
- The message type for the field. Must be a subclass of
Message.
- 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=True
if you use required=True
.
- repeated=False
- Whether or not this field is repeated. Mutually exclusive with the
required
argument; do not specify
required=True
if you use repeated=True
.
Raises a
FieldDefinitionError
if the message_type
is invalid.
Class Property
The MessageField class provides the following properties:
- type
- The Python type used for values of this field. For example, in the case
of DateTimeField,
type
is datetime.datetime
. For user defined
MessageFields, type
is the specified Message type.
- message_type
- The underlying message type used for serialization. Specifically this is
the type that you can store on an instance of a Message class. For example,
for DateTimeField,
the type will be
message_types.DateTimeMessage
. For normal
message fields it will be the protorpc message subclass. For example:
class Sub(messages.Message):
x = messages.IntegerField(1)
class M(messages.Message):
sub = messages.MessageField(Sub, 1)
dt = message_types.DateTimeField(2)
print 'M.sub.type =', M.sub.type
print 'M.sub.message_type =', M.sub.message_type
print 'M.dt.type =', M.dt.type
print 'M.dt.message_type =', M.dt.message_type
=== output ===
M.sub.type = <class '__main__.Sub>
M.sub.message_type = <class '__main__.Sub'>
M.dt.type = <type 'datetime.datetime'>
M.dt.message_type = <class 'protorpc.message_types.DateTimeMessage'>
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eMessageField\u003c/code\u003e class defines fields for sub-message values, enabling the efficient transmission of messages across network or process space.\u003c/p\u003e\n"],["\u003cp\u003eThe constructor of \u003ccode\u003eMessageField\u003c/code\u003e requires the \u003ccode\u003emessage_type\u003c/code\u003e and \u003ccode\u003enumber\u003c/code\u003e arguments, with optional \u003ccode\u003erequired\u003c/code\u003e and \u003ccode\u003erepeated\u003c/code\u003e arguments that are mutually exclusive.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003emessage_type\u003c/code\u003e specifies the message type of the field, and it must be a subclass of \u003ccode\u003eMessage\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003etype\u003c/code\u003e property of \u003ccode\u003eMessageField\u003c/code\u003e indicates the Python type used for the field's values, while \u003ccode\u003emessage_type\u003c/code\u003e reveals the underlying message type used for serialization.\u003c/p\u003e\n"]]],[],null,[]]