what's the right way to do polymorphism with protocol buffers?

后端 未结 6 2051
忘了有多久
忘了有多久 2020-12-04 17:50

I\'m trying to long-term serialize a bunch of objects related by a strong class hierarchy in java, and I\'d like to use protocol buffers to do it due to their simplicity, pe

6条回答
  •  再見小時候
    2020-12-04 18:13

    A solution a little better, for me, that the @Łukasz Marciniak's answer.

    If Bar extends Foo, simply write:

    message Bar {
       optional Foo foo = 1;
       optional double aDouble = 2;
    }
    message Foo {
       optional string aString = 1;
    }
    

    So if Foo evolves only Foo message is modified.

提交回复
热议问题