Gré*_*rel 5 c++ protocol-buffers
假设我有以下 protobuf 结构的两个实例:
message customStruct
{
optional int32 a = 1;
optional int32 b = 2;
}
message info
{
repeated customStruct cs = 1;
optional int32 x = 2;
optional double y = 3;
}
message root
{
optional info inf = 1;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以将消息与 C++ API 进行比较,但我想直接比较两个重复字段(customStruct此处)。
理想情况下,我需要 C# 方法Equals(RepeatedField< T > other)的 C++ 等效项的 C++ 等效项。
这在C++中可行吗?这是一个好的做法吗?
RepeatedField<T>有类似 STL 的迭代器,因此您可以用来std::equal比较它们:
#include <algorithm>
#include <...>
const google::protobuf::ReapeatedField<int32> & myField1 = ...;
const google::protobuf::ReapeatedField<int32> & myField2 = ...;
bool fieldsEqual = std::equal(myField1.begin(), myField1.end(), myField2.begin());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2000 次 |
| 最近记录: |