Thursday, 1 June 2017

Proto3 representing nested JSON structure

I'm wondering how I can represent a variable size JSON structure in my gRPC implementation with Node.js. I have a grpc service and a message that I want to receive the following structure:

{
  "Key": "Value",
  "Nested": { ... }
}

Here's my definition:

syntax = "proto3";

service Users {
  rpc RetrieveMeta (RetrieveMetaRequest) returns (RetrieveMetaResponse) {}
  rpc UpdateMeta   (UpdateMetaRequest)   returns (UpdateMetaResponse)   {}
}
message RetrieveMetaRequest {

}
message RetrieveMetaResponse {

}

I've read you can do so by importing a struct definition, however when I do that I get a file not found error as it performs a lookup within the current directory:

import "google/protobuf/struct.proto";

Throws:

/Users/ddibiase-macbook/Projects/dfx-api/node_modules/protobufjs/dist/protobuf.js:4720 throw Error("failed to import '"+importFilename+"' in '"+filename+"': file not found"); ^

Error: failed to import '/Users/ddibiase-macbook/Projects/dfx-api/protos/struct.proto'



via ddibiase

No comments:

Post a Comment