8
votes

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.

1
Have you tried adding one of those keywords where it says you should have one? What happens then? - takendarkk
Are you using the most recent protocol buffer compiler? oneof was added in 2.6, which appears to have been released last Monday. - Louis Wasserman
@LouisWasserman That was it, thanks! I didn't realize the oneof feature was new. If you want write your comment as the question, I can accept it as the answer. - yellavon

1 Answers

11
votes

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.