0

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'
Bidisha Pyne
  • 543
  • 2
  • 13
ddibiase
  • 1,412
  • 1
  • 20
  • 44

1 Answers1

1

You need to add a copy to your project source. Struct.proto doesn't come with the protoc compiler by default.

If you have the full sources for protobuf you can reference them from your project using the -I include directive pointed at the google/protobuf/ directory.

Carl Mastrangelo
  • 5,970
  • 1
  • 28
  • 37