Protobuf: "Timestamp" is not defined

Created on 20 Nov 2015  路  8Comments  路  Source: protocolbuffers/protobuf

After downloading, compiling, and installing the current master branch of google/protobuf (fa8e291), I'm unable to compile the following protobuf message with a Timestamp field:

syntax = "proto3";                                                                                                                                                     

message Foo {                                                                                                                                                          
        Timestamp bar = 1;                                                                                                                                             
}

Here's the output I received after trying to compile this message for a ruby project:

kellydunn in ~/work/test
$ protoc --ruby_out=. app/wire/proto/*.proto
app/wire/proto/test.proto:4:9: "Timestamp" is not defined.
make: *** [proto] Error 1

Here's some information about my current protoc tool used to compile the message:

kellydunn in ~/work/test
$ which protoc
/usr/local/bin/protoc

kellydunn in ~/work/test
$ protoc --version
libprotoc 3.0.0

Is there something I'm missing? Am I not referencing Timestamp correctly? Thanks in advance!

packaging & distribution ruby

Most helpful comment

You need to 'import "google/protobuf/timestamp.proto";' before using it. Also the name of the type is "google.protobuf.Timestamp".

All 8 comments

You need to 'import "google/protobuf/timestamp.proto";' before using it. Also the name of the type is "google.protobuf.Timestamp".

Ah gotcha, that does seem to work for the compile step, but when I run my ruby program, I now get a new error saying that it cannot find google/protobuf/timestamp. I actually don't see any reference to the Timestamp message in the generated ruby classes, would would lead me to believe that maybe there's an issue with the ruby compilation step.

google/protobuf/timestamp should be compiled into the ruby proto runtime (just like what other languages do). I guess this hasn't been implemented in ruby yet. @haberman

@xfxyjwf, @kellydunn, any updates to this? when other languages will be supported?
And most surprisingly that golang is not supported?

Using golang it also compiles but wont work as go cant find the package cannot find package "google/protobuf"... why it compiles but doesnt work why it even compiles if it wont work? ))

I've managed to compile using google.protobuf.Timestamp type rather than just Timestamp with the latest 3.0.0-beta2 in case that helps someone else, but the generated import statement for Go is incorrect. For Go, this PR will fix the import statement: https://github.com/google/protobuf/pull/1361. E.g.

syntax = "proto3";
package foo;
import "google/protobuf/timestamp.proto";

message Foo {
    google.protobuf.Timestamp timestamp = 1;
}

I've fixed the generated code temporarily by using import google_protobuf "github.com/golang/protobuf/ptypes/timestamp" instead of import google_protobuf "google/protobuf" but that's obviously not great given it gets overwritten on each generation. Hopefully the PR will get merged soon and a new version will be released.

Also I was wondering whether it will be possible to use the shorter Timestamp instead of google.protobuf.Timestamp?

I believe ruby now has well-known types packaged. @haberman can you confirm and close this if it's fixed?

Yes, the official packages now include the well-known types. Closing this issue.

When I encountered this issue with Go, I'd forgotten to copy the include directory from the protobuf distribution zip so that the Google Protocol Buffers files are found at /usr/local/include/google/protobuf on my machine.

Then I could use:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
}

message SearchResponse {
  repeated SearchResult results = 1;
  google.protobuf.Timestamp modified = 2;
}

message SearchResult {
  int64 id = 1;
  string url = 2;
  string description = 3;
}

And successfully generate Go files with protoc --go_out=. *.proto.

Was this page helpful?
0 / 5 - 0 ratings