Re: [protobuf] Decoding and making sense of MessageDifferencer output from Google Protobuf APIs

208 views
Skip to first unread message

Adam Cozzette

unread,
May 28, 2019, 1:08:38 PM5/28/19
to Kiran Kumar, Protocol Buffers
Which language are you using? I'm not sure about Java but in C++ I believe you can provide an implementation of the Reporter class and call MessageDifferencer::ReportDifferencesTo(). That will then give you all the information without you needing to parse the summary string.

On Sat, May 25, 2019 at 7:34 PM Kiran Kumar <kiranku...@gmail.com> wrote:
I am using MessageDifferencer API to compute difference between two Google Protobuf messages. I passed the below two messages to the API. 


name: "MSG1"

cfgMsg {

  cfgName: "obj1"

  msgId: 100

  cfgObj {

    uuid: "obj1_1"

    node_id: "1.1.1.1"

    intf_id: 100

  }

  cfgObj {

    uuid: "obj1_2"

    node_id: "2.2.2.2"

    intf_id: 200

  }

  cfgObj {

    uuid: "obj1_3"

    node_id: "3.3.3.3"

    intf_id: 300

  }

}

name: "MSG2"

cfgMsg {

  cfgName: "obj2"

  msgId: 200

  cfgObj {

    uuid: "obj1_1"

    node_id: "1.1.1.1"

    vrf_id: 100

  }

  cfgObj {

    uuid: "obj1_2"

    node_id: "4.4.4.4"

    vrf_id: 200

  }

  cfgObj {

    uuid: "obj1_3"

    node_id: "3.3.3.3"

    intf_id: 300

  }

  cfgObj {

    uuid: "obj1_5"

    router_id: "5.5.5.5"

    vrf_id: 500

  }

 
Output from the Message Differencer API is as below.

```
Message Differences:
modified: name: "MSG1" -> "MSG2"
modified: cfgMsg.cfgName: "obj1" -> "obj2"
modified: cfgMsg.msgId: 100 -> 200
modified: cfgMsg.cfgObj[1].router_id: "2.2.2.2" -> "4.4.4.4"
added: cfgMsg.cfgObj[3]: { uuid: "obj1_5" router_id: "5.5.5.5" vrf_id: 500 }
```

My question about this API is: Why does the output is in this format ? It is not really in any usable format for anyone who is calling this API. The calling application has to literally do a string parse to make sense of this output and conclude anything from the returned output. Also, this output will change depending on how the original message was defined so getting this parsing in a right way is pretty complex. In fact, even after parsing it is difficult to match with original message type with either FieldDescriptor, Reflection or Descriptor. Ideally, returning a new object of original message type with changed values would make more sense to me. 

Do I understand this API correctly or Am I interpreting the above API usage in a wrong way ? I don't know if this should be used in conjunction with any other API to make sense ? 

It will be really helpful for me and I really appreciate if any expect on this group could explain few details around this ?

Thanks,
Kiran

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/b4b52541-8522-418f-9330-b3f839035947%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hao Nguyen

unread,
May 28, 2019, 1:13:01 PM5/28/19
to Adam Cozzette, Kiran Kumar, Protocol Buffers
MessageDifferencer can be quite useful in tests. If you are comparing an actual proto against an expected proto and they don't match, then MessageDifferencer can tell you the delta in the test output.


Reply all
Reply to author
Forward
0 new messages