Google Protobuf empty fields and messages criteria (Python)

Suppose I have the following protobuf file definitions:

syntax = "proto2";
message request {
  optional string a = 1;
  optional bytes b = 2;
}
message dummy {
  optional string u = 1;
  optional request v = 2;
}

The following are my doubts/requirements:

  • Check if any of the fields is set or not in "request" object?
  • Check if the field "u" is set in "dummy" object?
  • Check if the field "v" is set (meaning if any of the internal fields are set to some value) in "dummy" object?
  • How to deal with situations involving fields having default values?
  • Write the code in such a manner so that it is compatible with version 3 of Google protobufs too.
  • I tried creating 2 objects "p" and "q" of type dummy object. Initially, both of them returned "False" on the condition "HasField("v")". Then I tried to copy field "v" from "q" to "p" using the code: "pvCopyFrom(qv)". But now, object "p" returned "True" on the condition "HasField("v")". Why does this happen?
  • My codebase is currently using python version 2.7.5 and protobuf version 2.6. It can happen I may upgrade the python and protobuf versions in future. Hence, would like to know if I could write code in such a manner which is compatible across versions.

    链接地址: http://www.djcxy.com/p/77292.html

    上一篇: 在nexus中使用安卓相机捕获图像后的空指针5

    下一篇: Google Protobuf空字段和消息标准(Python)