What's the preferred way to encode a “nullable” field in protobuf 2?

前端 未结 2 1562
醉梦人生
醉梦人生 2021-02-06 01:27

I am defining a ProtoBuf message where I want to have a \"nullable\" field -- i.e., I want to distinguish between the field having a value and not having a value. As a concrete

2条回答
  •  醉话见心
    2021-02-06 02:10

    Have a notion of NaN for each of the types and then use default (as shown below) to set it as the value. This will be used if nothing is specified for that particular field.

    optional float x = 1 [default = -1];
    

提交回复
热议问题