[erlang-questions] BERT vs protobuf in the erlang world

Vincent de Phily vincent.dephily@REDACTED
Thu Aug 25 12:04:15 CEST 2011


On Wednesday 24 August 2011 15:15:57 Jon Watte wrote:
> You solve that in one of two ways:
> 1) Create a message that is the "PDU" that contains the union of everything
> that could be sent,
> or
> 2) Create a wrapper that is just "type" followed by "binary data that is a
> marshaled message."
> 
> If you believe that the entirety of a protocol should be described by that
> protocol, then 1) is actually a fine solution. The preserve-and-forward
> semantic of unknown field ids means that forward compatibility is still
> possible.
> 
> message MyProtocolPDU {
>   optional SomeMessage some_message = 1;
>   optional AnotherMessage other_message = 2;
>   ...
> }
> 
> So, encoding a MyProtocolPDU that contains a SomeMessage will end up being
> different than encoding a MyProtocolPDU that contains an AnotherMessage.
> At the high level, you have to know that there is only one member in each
> MyProtocolPDU; I find that to be quite acceptable.

Yup, they're reasonable solutions (as long as you planed ahead). 2) may be 
ugly and innefficient, but it has been used as a pragmatic solution in 
countless formats. 1) works as long as you control the sender or you have a 
well-defined policy when multiple fields are present, but I'd otherwise 
consider it a footgun. I really find it odd that protobuf doesn't provide a 
CHOICE construct.

-- 
Vincent de Phily



More information about the erlang-questions mailing list