Given a Go struct like this:
type House struct {
Address string
Rooms []struct {
Name string
Windows int
Doors int
}
}
Or an equivalent JSON representation:
{
"address": ""
"rooms": [
{
"name": ""
"windows": 0
"doors": 0
}
]
}
What would the equivalent Protocol Buffer representation be?
This is more or less what I would like to do (althought not a valid Proto syntax):
message House {
string address = 1;
repeated message {
string name = 3;
int32 windows = 4;
int32 doors = 5;
} rooms = 2;
}
Instead, doing it like this is valid, but doesn't represent the data accurately since the original rooms
slice contains anonymous objects:
message House {
string address = 1;
repeated room rooms = 2;
}
message room {
string name = 1;
int32 windows = 2;
int32 doors = 3;
}
Update: I think I misunderstood how the message declaration works. The second example I gave should be sufficient and actually does not interfere with JSON unmarshalling.