-1

I want to make response in proto which is something like this in REST format :

response  = {
  "cars":[{'asd':1 , 'date': 1},{'asd':1 , 'date': 1},{'asd':1 , 'date': 1}],
  "houses":[{'asd':1 , 'date':Flexible Savings 1},{'asd':1 , 'date': 1},{'asd':1 , 'date': 1}],
}

how I Can write its proto file? And 2ndly in case I am not sure how many arrays I have to append in responce in that case what is practice need to be followed in grpc proto?

Ninja
  • 241
  • 2
  • 3
  • 13

1 Answers1

2
message Response {
    repeated Thing cars = 1;
    repeated Thing houses = 2;
}
message Thing {
    int32 asd = 1;
    int32 date = 2;
}

This may change a little depending on whether the two shapes (cars and houses) are the same, and whether the asd and date are actually integers. You might need a Car and House message type, and you might want a "timestamp" for "date".

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • thanks for answer sir , And can you please guide about If I don't know Number of arrays need to return ? Like It can be 4,5 ...100 . then ? – Ninja Apr 03 '21 at 21:58
  • @Ninja context? Maybe you need a `map` where a `Something` *has* a `repeated Thing`? – Marc Gravell Apr 03 '21 at 21:59
  • Can you sir provide any link etc ? I am newbie in this so can't understand properly – Ninja Apr 03 '21 at 22:03
  • @Ninja have you read the schema language overview? https://developers.google.com/protocol-buffers/docs/proto3 – Marc Gravell Apr 04 '21 at 08:44