首页 > 解决方案 > 在 C++ 协议缓冲区中具有相同类型的一个

问题描述

我有这样的消息:

message Foo {
    oneof Value {
        string a;
        string b;
        string c;
        string d;
        string e;
    }
}

如何oneof通过避免编写如下内容来写入然后读取字段:

if (choose_a)
    write a
else if (choose_b)
    write b
...

if (a is set)
    read from a
else if (b is set)
    read from b   
... 

标签: c++protocol-buffers

解决方案


推荐阅读