Python 2.7 はサポートが終了しており、2026 年 1 月 31 日に
非推奨になります。非推奨になると、過去に組織のポリシーを使用して以前のランタイムのデプロイを再度有効にしていた場合でも、Python 2.7 アプリケーションをデプロイできなくなります。既存の Python 2.7 アプリケーションは、
非推奨日以降も引き続き実行され、トラフィックを受信します。
サポートされている最新バージョンの Python に移行することをおすすめします。
MessageField クラス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
MessageField クラスは、ネットワークまたは処理空間全体で効率的に伝達されるようにメッセージを定義するために使用されます。メッセージはフィールド クラスを使用して定義されます。
MessageField
は、protorpc.messages
モジュールによって提供されます。
コンストラクタ
MessageField クラスのコンストラクタは、次のように定義されます。
-
class MessageField(message_type,
number,
[required=False | repeated=False])
-
サブメッセージの値のフィールドを定義します。
引数
- message_type
- フィールドのメッセージの型です。Message のサブクラスでなければなりません。
- number
- フィールドの番号。メッセージ クラスごとに一意でなければなりません。
- required=False
- このフィールドが必須かどうかを指定します。
repeated
引数と同時に指定することはできません。required=True
を使用する場合、repeated=True
は指定しないでください。
- repeated=False
- このフィールドが反復フィールドかどうかを指定します。
required
引数と同時に指定することはできません。repeated=True
を使用する場合、required=True
は指定しないでください。
message_type
が無効な場合は FieldDefinitionError を送出します。
クラスのプロパティ
MessageField クラスには次のプロパティがあります。
- type
- このフィールドの値に使用される Python 型。たとえば、DateTimeField の場合、
type
は datetime.datetime
です。ユーザー定義の MessageField の場合、type
は指定のメッセージ型です。
- message_type
- シリアル化に使用される基本的なメッセージ型。具体的には、Message クラスのインスタンスに格納できる型です。たとえば、DateTimeField の場合、型は
message_types.DateTimeMessage
になります。通常のメッセージ フィールドの場合、protorpc メッセージ サブクラスになります。次に例を示します。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'>
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 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,["# The MessageField Class\n\nThe MessageField class is used to define messages for efficient transmission\nacross network or process space. Messages are defined using\n[field\nclasses](/appengine/docs/legacy/standard/python/tools/protorpc/messages/fieldclasses).\n\n`MessageField` is provided by the `protorpc.messages`\nmodule.\n\nConstructor\n-----------\n\nThe constructor of the MessageField class is defined as follows:\n\n\nclass MessageField(message_type,\nnumber,\n\\[required=False \\| repeated=False\\])\n\n: Defines fields for sub-message values.\n\n **Arguments**\n\n message_type\n : The message type for the field. Must be a subclass of\n [Message](/appengine/docs/legacy/standard/python/tools/protorpc/messages/messageclass).\n\n number\n : Number of the field. Must be unique per message class.\n\n required=False\n : Whether or not this field is required. Mutually exclusive with the\n `repeated` argument; do not specify\n `repeated=True` if you use `required=True`.\n\n repeated=False\n : Whether or not this field is repeated. Mutually exclusive with the\n `required` argument; do not specify\n `required=True` if you use `repeated=True`.\n\n Raises a\n [FieldDefinitionError](/appengine/docs/legacy/standard/python/tools/protorpc/messages/exceptions#FieldDefinitionError)\n if the `message_type` is invalid.\n\nClass Property\n--------------\n\nThe MessageField class provides the following properties:\n\ntype\n: The Python type used for values of this field. For example, in the case\n of [DateTimeField](/appengine/docs/legacy/standard/python/tools/protorpc/messages/datetimefieldclass),\n `type` is `datetime.datetime`. For user defined\n MessageFields, `type` is the specified Message type.\n\nmessage_type\n: The underlying message type used for serialization. Specifically this is\n the type that you can store on an instance of a Message class. For example,\n for [DateTimeField](/appengine/docs/legacy/standard/python/tools/protorpc/messages/datetimefieldclass),\n the type will be `message_types.DateTimeMessage`. For normal\n message fields it will be the protorpc message subclass. For example:\n\n ```python\n class Sub(messages.Message):\n x = messages.IntegerField(1)\n\n class M(messages.Message):\n sub = messages.MessageField(Sub, 1)\n dt = message_types.DateTimeField(2)\n\n print 'M.sub.type =', M.sub.type\n print 'M.sub.message_type =', M.sub.message_type\n print 'M.dt.type =', M.dt.type\n print 'M.dt.message_type =', M.dt.message_type\n\n\n === output ===\n M.sub.type = \u003cclass '__main__.Sub\u003e\n M.sub.message_type = \u003cclass '__main__.Sub'\u003e\n M.dt.type = \u003ctype 'datetime.datetime'\u003e\n M.dt.message_type = \u003cclass 'protorpc.message_types.DateTimeMessage'\u003e\n ```"]]