Protobuf import failure
Asked Answered
A

2

19

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.

Augustaugusta answered 14/12, 2016 at 19:37 Comment(0)
A
43

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). Example:

base.proto

syntax = "proto3";
option csharp_namespace = "Api.Protos";
package base;
message BaseResponse {
    bool IsSuccess = 1;
    string Message = 2;
}

user.proto

syntax = "proto3";
import "Protos/base.proto";
option csharp_namespace = "Api.Protos";
package user;

message UserCreateResponse {
    base.BaseResponse response = 1;
}
Augustaugusta answered 14/12, 2016 at 19:46 Comment(0)
B
0

Seems import from root but not current proto file's folder. So you need add 'Proto/a.proto' if all your proto files are under Proto folder.

Biota answered 21/11, 2021 at 2:55 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Borders

© 2022 - 2024 — McMap. All rights reserved.