LLVM  8.0.1
MsgPackWriter.h
Go to the documentation of this file.
1 //===- MsgPackWriter.h - Simple MsgPack writer ------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file contains a MessagePack writer.
12 ///
13 /// See https://github.com/msgpack/msgpack/blob/master/spec.md for the full
14 /// specification.
15 ///
16 /// Typical usage:
17 /// \code
18 /// raw_ostream output = GetOutputStream();
19 /// msgpack::Writer MPWriter(output);
20 /// MPWriter.writeNil();
21 /// MPWriter.write(false);
22 /// MPWriter.write("string");
23 /// // ...
24 /// \endcode
25 ///
26 ///
27 //===----------------------------------------------------------------------===//
28 
29 #ifndef LLVM_SUPPORT_MSGPACKPARSER_H
30 #define LLVM_SUPPORT_MSGPACKPARSER_H
31 
36 
37 namespace llvm {
38 namespace msgpack {
39 
40 /// Writes MessagePack objects to an output stream, one at a time.
41 class Writer {
42 public:
43  /// Construct a writer, optionally enabling "Compatibility Mode" as defined
44  /// in the MessagePack specification.
45  ///
46  /// When in \p Compatible mode, the writer will write \c Str16 formats
47  /// instead of \c Str8 formats, and will refuse to write any \c Bin formats.
48  ///
49  /// \param OS stream to output MessagePack objects to.
50  /// \param Compatible when set, write in "Compatibility Mode".
51  Writer(raw_ostream &OS, bool Compatible = false);
52 
53  Writer(const Writer &) = delete;
54  Writer &operator=(const Writer &) = delete;
55 
56  /// Write a \em Nil to the output stream.
57  ///
58  /// The output will be the \em nil format.
59  void writeNil();
60 
61  /// Write a \em Boolean to the output stream.
62  ///
63  /// The output will be a \em bool format.
64  void write(bool b);
65 
66  /// Write a signed integer to the output stream.
67  ///
68  /// The output will be in the smallest possible \em int format.
69  ///
70  /// The format chosen may be for an unsigned integer.
71  void write(int64_t i);
72 
73  /// Write an unsigned integer to the output stream.
74  ///
75  /// The output will be in the smallest possible \em int format.
76  void write(uint64_t u);
77 
78  /// Write a floating point number to the output stream.
79  ///
80  /// The output will be in the smallest possible \em float format.
81  void write(double d);
82 
83  /// Write a string to the output stream.
84  ///
85  /// The output will be in the smallest possible \em str format.
86  void write(StringRef s);
87 
88  /// Write a memory buffer to the output stream.
89  ///
90  /// The output will be in the smallest possible \em bin format.
91  ///
92  /// \warning Do not use this overload if in \c Compatible mode.
93  void write(MemoryBufferRef Buffer);
94 
95  /// Write the header for an \em Array of the given size.
96  ///
97  /// The output will be in the smallest possible \em array format.
98  //
99  /// The header contains an identifier for the \em array format used, as well
100  /// as an encoding of the size of the array.
101  ///
102  /// N.B. The caller must subsequently call \c Write an additional \p Size
103  /// times to complete the array.
105 
106  /// Write the header for a \em Map of the given size.
107  ///
108  /// The output will be in the smallest possible \em map format.
109  //
110  /// The header contains an identifier for the \em map format used, as well
111  /// as an encoding of the size of the map.
112  ///
113  /// N.B. The caller must subsequently call \c Write and additional \c Size*2
114  /// times to complete the map. Each even numbered call to \c Write defines a
115  /// new key, and each odd numbered call defines the previous key's value.
116  void writeMapSize(uint32_t Size);
117 
118  /// Write a typed memory buffer (an extension type) to the output stream.
119  ///
120  /// The output will be in the smallest possible \em ext format.
121  void writeExt(int8_t Type, MemoryBufferRef Buffer);
122 
123 private:
125  bool Compatible;
126 };
127 
128 } // end namespace msgpack
129 } // end namespace llvm
130 
131 #endif // LLVM_SUPPORT_MSGPACKPARSER_H
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Writer & operator=(const Writer &)=delete
void writeExt(int8_t Type, MemoryBufferRef Buffer)
Write a typed memory buffer (an extension type) to the output stream.
void writeMapSize(uint32_t Size)
Write the header for a Map of the given size.
Writer(raw_ostream &OS, bool Compatible=false)
Construct a writer, optionally enabling "Compatibility Mode" as defined in the MessagePack specificat...
Writes MessagePack objects to an output stream, one at a time.
Definition: MsgPackWriter.h:41
void writeNil()
Write a Nil to the output stream.
void writeArraySize(uint32_t Size)
Write the header for an Array of the given size.
void write(bool b)
Write a Boolean to the output stream.
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:52
uint32_t Size
Definition: Profile.cpp:47
This file contains constants used for implementing MessagePack support.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49