首页 > 解决方案 > 原始消息上的 MessageDifferencer 是否处理映射?

问题描述

我必须检查我的程序(C++)的两个 protobuf 消息之间的差异。我正在为此尝试MessageDifferencer::CompareMessageDifferencer::Equals

map在 proto 消息中有一个字段,据我们所知,它不能保证被订购。所以,我想知道MessageDifferencer对此有何看法?有没有人出局CompareEquals职能部门有东西可以处理这种情况?

我的意思是,如果地图没有排序,我们如何确定第一条消息中的所有元素都与第二条消息中的正确元素进行了比较?

我的信息是这样的:

message foo
{
    // some-fields
    map<string, int64> bar = 2;
    // more-fields
}

我是 C++ 和 protobuf 的新手,所以任何正确方向的想法都会有所帮助。

更新:

即使我比较相同的消息,它也显示不匹配,我可以在差异报告中看到这是因为相同的字段没有相互匹配。

从 protobuf文档

Wire format ordering and map iteration ordering of map values is undefined, so you cannot rely on your map items being in a particular order.

标签: c++protocol-buffersproto

解决方案


推荐阅读