//===-- MsgPackDocument.cpp - MsgPack Document --------------------------*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// This file implements a class that exposes a simple in-memory representation /// of a document of MsgPack objects, that can be read from MsgPack, written to /// MsgPack, and inspected and modified in memory. This is intended to be a /// lighter-weight (in terms of memory allocations) replacement for /// MsgPackTypes. /// //===----------------------------------------------------------------------===// #include "llvm/BinaryFormat/MsgPackDocument.h" #include "llvm/BinaryFormat/MsgPackWriter.h" usingnamespacellvm; usingnamespacemsgpack; // Convert this DocNode into an empty array. void DocNode::convertToArray() { … } // Convert this DocNode into an empty map. void DocNode::convertToMap() { … } /// Find the key in the MapDocNode. DocNode::MapTy::iterator MapDocNode::find(StringRef S) { … } /// Member access for MapDocNode. The string data must remain valid for the /// lifetime of the Document. DocNode &MapDocNode::operator[](StringRef S) { … } /// Member access for MapDocNode. DocNode &MapDocNode::operator[](DocNode Key) { … } /// Member access for MapDocNode for integer key. DocNode &MapDocNode::operator[](int Key) { … } DocNode &MapDocNode::operator[](unsigned Key) { … } DocNode &MapDocNode::operator[](int64_t Key) { … } DocNode &MapDocNode::operator[](uint64_t Key) { … } /// Array element access. This extends the array if necessary. DocNode &ArrayDocNode::operator[](size_t Index) { … } // Convenience assignment operators. This only works if the destination // DocNode has an associated Document, i.e. it was not constructed using the // default constructor. The string one does not copy, so the string must // remain valid for the lifetime of the Document. Use fromString to avoid // that restriction. DocNode &DocNode::operator=(StringRef Val) { … } DocNode &DocNode::operator=(MemoryBufferRef Val) { … } DocNode &DocNode::operator=(bool Val) { … } DocNode &DocNode::operator=(int Val) { … } DocNode &DocNode::operator=(unsigned Val) { … } DocNode &DocNode::operator=(int64_t Val) { … } DocNode &DocNode::operator=(uint64_t Val) { … } // A level in the document reading stack. struct StackLevel { … }; // Read a document from a binary msgpack blob, merging into anything already in // the Document. // The blob data must remain valid for the lifetime of this Document (because a // string object in the document contains a StringRef into the original blob). // If Multi, then this sets root to an array and adds top-level objects to it. // If !Multi, then it only reads a single top-level object, even if there are // more, and sets root to that. // Returns false if failed due to illegal format or merge error. bool Document::readFromBlob( StringRef Blob, bool Multi, function_ref<int(DocNode *DestNode, DocNode SrcNode, DocNode MapKey)> Merger) { … } struct WriterStackLevel { … }; /// Write a MsgPack document to a binary MsgPack blob. void Document::writeToBlob(std::string &Blob) { … }