Error/problem using constants! ("Expected top-level statement (e.g. "message")")

2,018 views
Skip to first unread message

Leonardo Toledo

unread,
Mar 20, 2017, 1:08:40 PM3/20/17
to Protocol Buffers
Hi! I am writing my "file.proto" and when i write a constant the compiler give an error called "Expected top-level statement (e.g. "message")" and i do not know why! In my "file.proto" i have the follow:

"message Test{
string str1 = 1;
DataType data = 2;

DataType = DataOther | DataTest;"

This piece above of code is a part of what i have in my "file.proto" and i want define the variable "Datatype" as a constant that can be of 2 different types, being them, DataOther or DataTest. But when i am compiling, the compiler give me the error that i mencioned. Can anyone help me please, because i do not know how solve this problem!?

Thanks in advance and i am waiting for some answer, 
Leonardo Toledo

Adam Cozzette

unread,
Mar 20, 2017, 1:27:24 PM3/20/17
to Leonardo Toledo, Protocol Buffers
The compiler doesn't support that syntax (DataType = DataOther | DataTest). Maybe a oneof field is what you are looking for; that would look something like this:

message DataType {
  oneof data_type {
    DataOther data_other = 1;
    DataTest data_test = 2;
  }
}

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages