This is an archive of the discontinued LLVM Phabricator instance.

[MsgPack] Added convenience assignment to MsgPackDocument
ClosedPublic

Authored by tpr on May 18 2020, 6:50 AM.

Details

Summary

This commit increases the convenience of using the MsgPackDocument API,
especially when creating a document for writing out.

It adds direct assignment of bool, integer and string types to a
DocNode, as long as that DocNode is already inside a document, e.g. the
result of a map lookup. It also adds map lookup given an integer type
(it already had that for string).

So, to assign a string to a map element whose key is an int, you can
now write

MyMap[42] = "towel";

instead of

MyMap[MyMap.getDocument()->getNode(42)] =
    MyMap.getDocument()->getNode("towel");

Change-Id: I17301fa15bb9802231c52542798af5b54beb583e

Diff Detail

Event Timeline

tpr created this revision.May 18 2020, 6:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2020, 6:50 AM
tpr updated this revision to Diff 264610.May 18 2020, 6:56 AM

V2: Added tests

tpr updated this revision to Diff 264656.May 18 2020, 9:14 AM

V3: Added assignment for const char *, otherwise it defaults to using

the bool one rather than the StringRef one.
scott.linder accepted this revision.May 19 2020, 8:52 AM
This revision is now accepted and ready to land.May 19 2020, 8:52 AM
tpr updated this revision to Diff 265357.May 20 2020, 3:04 PM

V4: Added MapDocNode::erase methods.

This revision was automatically updated to reflect the committed changes.