Search code examples
goprotocol-buffersprotobuf-javaprotobuf-cprotobuf-go

When I'm trying to compile the Protobuf in golang, It's showing '"int" is not defined.'


While compiling the proto file, I'm getting '"int" is not defined'.

'test.proto' file

syntax = "proto3";

package test;

option go_package = "/;test";

message User {
    string FirstName = 1;
    string LastName = 2;
    string Address = 3;
    int Contact = 4;
    int Age = 5;
}
Output:
test.proto:11:5: "int" is not defined.

Solution

  • int is not a scalar type in proto3. You must use one of the valid scalar value types as specified:

    https://developers.google.com/protocol-buffers/docs/proto3#scalar

    Replacing int with int32:

    syntax = "proto3";
    
    package test;
    
    option go_package = "/;test";
    
    message User {
        string FirstName = 1;
        string LastName = 2;
        string Address = 3;
        int32 Contact = 4;
        int32 Age = 5;
    }