Does anyone know where I can find an example of a gRPC protobuf file that imports from a different file and uses a protobuf message in a return? I can't find any at all.
I have a file...
syntax = "proto3";
package a1;
import "a.proto";
service mainservice {
rpc DoSomething(...) returns (a.SomeResponse) {}
}
a.proto is also in the same directory and also compiles by itself. The error messages I'm getting are:
"a.SomeResponse" is not defined.
mainfile.proto: warning: Import a.proto but not used.
To import another .proto 's definitions, you add an import statement to the top of your file: import "myproject/other_protos.proto"; By default, you can use definitions only from directly imported .proto files. However, sometimes you may need to move a .proto file to a new location.
Protocol buffers (Protobuf) are a language-agnostic data serialization format developed by Google. Protobuf is great for the following reasons: Low data volume: Protobuf makes use of a binary format, which is more compact than other formats such as JSON. Persistence: Protobuf serialization is backward-compatible.
The . proto file starts with a package declaration, which helps to prevent naming conflicts between different projects.
-I and --proto_path are the same flag: -I is the shorthand version. The purpose of the flag is to specify a directory in which to look for imported files, much like the C compiler's -I flag, Java's CLASSPATH environment variable, Python's PYTHONPATH , etc.
Found the answer... need to make sure the package name of a.proto is used when specifying the object imported (eg a_package_name.SomeResponse)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With