Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf "oneof" functionality not working

I have a this sample protobuf message:

message testMessage{    
    oneof oneOfTest{
        string test2 = 2;
        int32 test3 = 3;   
    } 
}

But it is failing to compile, saying:

[ERROR] protoc failed error: Expected "required", "optional", or "repeated".
test.proto: Missing field number.

Based on the line numbers, it is looking for that required/optional/repeated keyworkd before "oneof" and it is complaining of the missing field number after "oneOfTest". Is this not the correct way to use oneof? I am using the java compiler for Protobuf.

like image 458
yellavon Avatar asked Sep 02 '14 17:09

yellavon


People also ask

What is oneof in protobuf?

Protocol Buffer (Protobuf) provides two simpler options for dealing with values that might be of more than one type. The Any type can represent any known Protobuf message type. And you can use the oneof keyword to specify that only one of a range of fields can be set in any message.

How do I add comments to a proto file?

Adding Comments To add comments to your .proto files, use C/C++-style // and /* ... */ syntax.

Does protobuf support inheritance?

Protobuf doesn't support inheritance. Having a common header and using composition is the best solution. You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.


1 Answers

Make sure you're using the most recent version of the protocol buffer compiler: oneof syntax was added in only the very most recent version, released last Monday.

like image 91
Louis Wasserman Avatar answered Sep 23 '22 11:09

Louis Wasserman