You can define and use message types inside other message types, as in the following example – here the Result message is defined inside the SearchResponse message:
如同接下來的例子一樣,你可以在其他message類型中定義和使用message類型 - Result message 定義在了 SearchResponse message 內(nèi)部:
message SearchResponse {
message Result {
string url = 1;
string title = 2;
repeated string snippets = 3;
}
repeated Result results = 1;
}
If you want to reuse this message type outside its parent message type, you refer to it as _Parent_._Type_:
如果你想在父message類型之外使用該內(nèi)嵌message類型,你可以使用_Parent_._Type_引用它
message SomeOtherMessage {
SearchResponse.Result result = 1;
}
You can nest messages as deeply as you like:
你可以根據(jù)自己的喜好將message類型嵌套到任意深度:
message Outer { // Level 0
message MiddleAA { // Level 1
message Inner { // Level 2
int64 ival = 1;
bool booly = 2;
}
}
message MiddleBB { // Level 1
message Inner { // Level 2
int32 ival = 1;
bool booly = 2;
}
}
}