protocol-buffersproto3

How to declare arrays properly in google protobuf


Here is how I have defined a message:

message PhoneNumberAndTypes {
  repeated Type types = 1;
  Phone number = 2;
}

And when I added the types using .addTypes() and printed the object in console, it came out like below:

phone_numbers {
  types: HOME
  types: MOBILE
  phone_number {
    number: "9912300000"
  }
}

But I hoped for the types to be like [HOME,MOBILE].

What change should I make?


Solution

  • Actually its a List inside while I debugged it. The "printing" on console did not necessarily reflect the actual object properties.

    [HOME, MOBILE]