Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf timestamp not found

Relatively new to GRPC and getting an error in my proto file that I cannot seem to make sense of. I would like to send a time in a message using the "google.protobuf.Timestamp". I cannot seem to import it. What am I doing wrong?

syntax = "proto3";
    
import "google/protobuf/timestamp.proto";
        
service ProfileService {
    rpc ConstructProfileStructFromUser (ConstructProfileStructFromUserRequest) returns (ConstructProfileStructFromUserResponse);
}
        
message ConstructProfileStructFromUserRequest {
    string transactionID = 1;
    string User = 2;
}
        
message ConstructProfileStructFromUserResponse {
    string UID = 1;
    string ContactEmail = 2;
    google.protobuf.Timestamp DateOfBirth = 3;
}

Both in my IDE and my compiler (using the below command) then I get the error

google/protobuf/timestamp.proto: File not found.
profile.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
profile.proto:21:5: "google.protobuf.Timestamp" is not defined.

Command to run:

protoc -I profile/ profile/profile.proto --go_out=plugins=grpc:profile

Protoc --version

libprotoc 3.0.0
like image 578
mornindew Avatar asked May 07 '19 22:05

mornindew


People also ask

How do I import a protoc with a timestamp?

In your .proto import should look like (i.e. without path): Then in the protoc invocation you pass absolute path to your package directory containing timestamp.proto (I use github.com/golang/protobuf/ptypes/timestamp) using --proto_path option.

What is timestamp in proto3?

Syntax proto3. A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time. It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one.

How do I download and install Protobuf?

Manually download from github.com/google/protobuf/releases the zip file corresponding to your operating system and computer architecture (protoc--.zip), or fetch the file using commands such as the following: Unzip the file under $HOME/.local or a directory of your choice. For example:

Where does protoc expect imports to be placed?

It seems by default protoc expects imports to be present in an include path relative to the protoc installation directory. For example: Downloading a pre-compiled binary as indicated below will have the needed include directory.


2 Answers

I had this issue after installing the protoc compiler using the apt package manager (Ubuntu) and it put the protoc compiler somewhere like /usr/local/bin.

It seems by default protoc expects imports to be present in an include path relative to the protoc installation directory. For example:

  • protoc location: /usr/local/bin/protoc
  • include location: /usr/local/bin/include/*

Install pre-compiled binaries (any OS)

Downloading a pre-compiled binary as indicated below will have the needed include directory.

Instructions from grpc.io/docs/protoc-installation

  1. Manually download from github.com/google/protobuf/releases the zip file corresponding to your operating system and computer architecture (protoc--.zip), or fetch the file using commands such as the following:
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
  1. Unzip the file under $HOME/.local or a directory of your choice. For example:
unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
  1. Update your environment’s path variable to include the path to the protoc executable. For example:
export PATH="$PATH:$HOME/.local/bin"
like image 153
SwiftD Avatar answered Oct 16 '22 09:10

SwiftD


If you installed protoc with your package manager, you only have to install the libprotobuf-dev (Ubuntu) or protobuf-devel (Fedora) package.

In general, you can find the containing package of a file on Ubuntu with apt-file find google/protobuf/timestamp.proto or on Fedora dnf repoquery --file "**/google/protobuf/timestamp.proto" (this is how I found the package I needed). Other package managers probably have similar commands.

like image 2
T - Gott Avatar answered Oct 16 '22 09:10

T - Gott