|
|
|||
File indexing completed on 2026-05-10 08:43:22
0001 //===- MsgPackWriter.h - Simple MsgPack writer ------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// 0009 /// \file 0010 /// This file contains a MessagePack writer. 0011 /// 0012 /// See https://github.com/msgpack/msgpack/blob/master/spec.md for the full 0013 /// specification. 0014 /// 0015 /// Typical usage: 0016 /// \code 0017 /// raw_ostream output = GetOutputStream(); 0018 /// msgpack::Writer MPWriter(output); 0019 /// MPWriter.writeNil(); 0020 /// MPWriter.write(false); 0021 /// MPWriter.write("string"); 0022 /// // ... 0023 /// \endcode 0024 /// 0025 /// 0026 //===----------------------------------------------------------------------===// 0027 0028 #ifndef LLVM_BINARYFORMAT_MSGPACKWRITER_H 0029 #define LLVM_BINARYFORMAT_MSGPACKWRITER_H 0030 0031 #include "llvm/Support/EndianStream.h" 0032 #include "llvm/Support/MemoryBufferRef.h" 0033 0034 namespace llvm { 0035 0036 class raw_ostream; 0037 0038 namespace msgpack { 0039 0040 /// Writes MessagePack objects to an output stream, one at a time. 0041 class Writer { 0042 public: 0043 /// Construct a writer, optionally enabling "Compatibility Mode" as defined 0044 /// in the MessagePack specification. 0045 /// 0046 /// When in \p Compatible mode, the writer will write \c Str16 formats 0047 /// instead of \c Str8 formats, and will refuse to write any \c Bin formats. 0048 /// 0049 /// \param OS stream to output MessagePack objects to. 0050 /// \param Compatible when set, write in "Compatibility Mode". 0051 Writer(raw_ostream &OS, bool Compatible = false); 0052 0053 Writer(const Writer &) = delete; 0054 Writer &operator=(const Writer &) = delete; 0055 0056 /// Write a \em Nil to the output stream. 0057 /// 0058 /// The output will be the \em nil format. 0059 void writeNil(); 0060 0061 /// Write a \em Boolean to the output stream. 0062 /// 0063 /// The output will be a \em bool format. 0064 void write(bool b); 0065 0066 /// Write a signed integer to the output stream. 0067 /// 0068 /// The output will be in the smallest possible \em int format. 0069 /// 0070 /// The format chosen may be for an unsigned integer. 0071 void write(int64_t i); 0072 0073 /// Write an unsigned integer to the output stream. 0074 /// 0075 /// The output will be in the smallest possible \em int format. 0076 void write(uint64_t u); 0077 0078 /// Write a floating point number to the output stream. 0079 /// 0080 /// The output will be in the smallest possible \em float format. 0081 void write(double d); 0082 0083 /// Write a string to the output stream. 0084 /// 0085 /// The output will be in the smallest possible \em str format. 0086 void write(StringRef s); 0087 0088 /// Write a memory buffer to the output stream. 0089 /// 0090 /// The output will be in the smallest possible \em bin format. 0091 /// 0092 /// \warning Do not use this overload if in \c Compatible mode. 0093 void write(MemoryBufferRef Buffer); 0094 0095 /// Write the header for an \em Array of the given size. 0096 /// 0097 /// The output will be in the smallest possible \em array format. 0098 // 0099 /// The header contains an identifier for the \em array format used, as well 0100 /// as an encoding of the size of the array. 0101 /// 0102 /// N.B. The caller must subsequently call \c Write an additional \p Size 0103 /// times to complete the array. 0104 void writeArraySize(uint32_t Size); 0105 0106 /// Write the header for a \em Map of the given size. 0107 /// 0108 /// The output will be in the smallest possible \em map format. 0109 // 0110 /// The header contains an identifier for the \em map format used, as well 0111 /// as an encoding of the size of the map. 0112 /// 0113 /// N.B. The caller must subsequently call \c Write and additional \c Size*2 0114 /// times to complete the map. Each even numbered call to \c Write defines a 0115 /// new key, and each odd numbered call defines the previous key's value. 0116 void writeMapSize(uint32_t Size); 0117 0118 /// Write a typed memory buffer (an extension type) to the output stream. 0119 /// 0120 /// The output will be in the smallest possible \em ext format. 0121 void writeExt(int8_t Type, MemoryBufferRef Buffer); 0122 0123 private: 0124 support::endian::Writer EW; 0125 bool Compatible; 0126 }; 0127 0128 } // end namespace msgpack 0129 } // end namespace llvm 0130 0131 #endif // LLVM_BINARYFORMAT_MSGPACKWRITER_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|