Michael McLaughlin
Michael McLaughlin

Reputation: 605

grpc and protobuf with variable keys

I have a hash of key values pairs.

I do not have the keys, nor the values.

I can assume most will be there, but sometimes keys are removed and others are added. Is there any way for me to have a message with variable keys?

{
  "knownkey1": "value",
  "knownkey2": {
    "unknown-key1": "value",
    "unknown-key2": "value"
  }
}   

or is the best ways to just serialize it using json stringify in the message? i would think that would defeat the whole purpose of using grpc.

message Rate {
  string ticker = 1;
  string value = 2;
}

message GetAllResponse {
  string lastUpdated = 1;
  repeated Rate payload = 2;
}

Upvotes: 1

Views: 3784

Answers (1)

Michael McLaughlin
Michael McLaughlin

Reputation: 605

Looks like you can just use the maps type as outlined here: https://developers.google.com/protocol-buffers/docs/proto3#maps

Upvotes: 2

Related Questions