oneof field: define an empty member

160 views
Skip to first unread message

Maxim

unread,
Apr 8, 2020, 8:39:55 AM4/8/20
to Protocol Buffers
Hi all,

I am looking for some guidance what would be the best way to define a member of a oneof field where the actual value of the member does not matter and it is sufficient to know that it was selected.

A somewhat contrived example:

message SearchRequest {
    oneof options
{
       
ValueDoesNotMatter search_all = 1;
       
ValueDoesNotMatter search_starred = 2;
       
string search_named = 3;
   
}
}

My first choice would be an empty message like google.protobuf.Empty, but it seems that in C++ it is somewhat cumbersome to select that member:


message
.mutable_options().set_allocated_search_all(new google::protobuf::Empty);


I thought maybe I am doing it wrong and there is a better way?

Thanks,

Maxim


Reply all
Reply to author
Forward
0 new messages