21using namespace msgpack;
24 : InputBuffer(InputBuffer), Current(InputBuffer.getBufferStart()),
25 End(InputBuffer.getBufferEnd()) {}
43 case FirstByte::False:
49 return readInt<int8_t>(Obj);
50 case FirstByte::Int16:
52 return readInt<int16_t>(Obj);
53 case FirstByte::Int32:
55 return readInt<int32_t>(Obj);
56 case FirstByte::Int64:
58 return readInt<int64_t>(Obj);
59 case FirstByte::UInt8:
61 return readUInt<uint8_t>(Obj);
62 case FirstByte::UInt16:
64 return readUInt<uint16_t>(Obj);
65 case FirstByte::UInt32:
67 return readUInt<uint32_t>(Obj);
68 case FirstByte::UInt64:
70 return readUInt<uint64_t>(Obj);
71 case FirstByte::Float32:
73 if (
sizeof(
float) > remainingSpace())
74 return make_error<StringError>(
75 "Invalid Float32 with insufficient payload",
76 std::make_error_code(std::errc::invalid_argument));
78 llvm::bit_cast<float>(endian::read<uint32_t, Endianness>(Current));
79 Current +=
sizeof(float);
81 case FirstByte::Float64:
83 if (
sizeof(
double) > remainingSpace())
84 return make_error<StringError>(
85 "Invalid Float64 with insufficient payload",
86 std::make_error_code(std::errc::invalid_argument));
88 llvm::bit_cast<double>(endian::read<uint64_t, Endianness>(Current));
89 Current +=
sizeof(double);
93 return readRaw<uint8_t>(Obj);
94 case FirstByte::Str16:
96 return readRaw<uint16_t>(Obj);
97 case FirstByte::Str32:
99 return readRaw<uint32_t>(Obj);
100 case FirstByte::Bin8:
102 return readRaw<uint8_t>(Obj);
103 case FirstByte::Bin16:
105 return readRaw<uint16_t>(Obj);
106 case FirstByte::Bin32:
108 return readRaw<uint32_t>(Obj);
109 case FirstByte::Array16:
111 return readLength<uint16_t>(Obj);
112 case FirstByte::Array32:
114 return readLength<uint32_t>(Obj);
115 case FirstByte::Map16:
117 return readLength<uint16_t>(Obj);
118 case FirstByte::Map32:
120 return readLength<uint32_t>(Obj);
121 case FirstByte::FixExt1:
123 return createExt(Obj, FixLen::Ext1);
124 case FirstByte::FixExt2:
126 return createExt(Obj, FixLen::Ext2);
127 case FirstByte::FixExt4:
129 return createExt(Obj, FixLen::Ext4);
130 case FirstByte::FixExt8:
132 return createExt(Obj, FixLen::Ext8);
133 case FirstByte::FixExt16:
135 return createExt(Obj, FixLen::Ext16);
136 case FirstByte::Ext8:
138 return readExt<uint8_t>(Obj);
139 case FirstByte::Ext16:
141 return readExt<uint16_t>(Obj);
142 case FirstByte::Ext32:
144 return readExt<uint32_t>(Obj);
147 if ((FB & FixBitsMask::NegativeInt) == FixBits::NegativeInt) {
150 static_assert(
sizeof(
I) ==
sizeof(FB),
"Unexpected type sizes");
151 memcpy(&
I, &FB,
sizeof(FB));
156 if ((FB & FixBitsMask::PositiveInt) == FixBits::PositiveInt) {
162 if ((FB & FixBitsMask::String) == FixBits::String) {
165 return createRaw(Obj,
Size);
168 if ((FB & FixBitsMask::Array) == FixBits::Array) {
174 if ((FB & FixBitsMask::Map) == FixBits::Map) {
180 return make_error<StringError>(
181 "Invalid first byte", std::make_error_code(std::errc::invalid_argument));
185 if (
sizeof(
T) > remainingSpace())
186 return make_error<StringError>(
187 "Invalid Raw with insufficient payload",
188 std::make_error_code(std::errc::invalid_argument));
189 T Size = endian::read<T, Endianness>(Current);
190 Current +=
sizeof(
T);
191 return createRaw(Obj,
Size);
195 if (
sizeof(
T) > remainingSpace())
196 return make_error<StringError>(
197 "Invalid Int with insufficient payload",
198 std::make_error_code(std::errc::invalid_argument));
199 Obj.
Int =
static_cast<int64_t
>(endian::read<T, Endianness>(Current));
200 Current +=
sizeof(
T);
205 if (
sizeof(
T) > remainingSpace())
206 return make_error<StringError>(
207 "Invalid Int with insufficient payload",
208 std::make_error_code(std::errc::invalid_argument));
209 Obj.
UInt =
static_cast<uint64_t>(endian::read<T, Endianness>(Current));
210 Current +=
sizeof(
T);
215 if (
sizeof(
T) > remainingSpace())
216 return make_error<StringError>(
217 "Invalid Map/Array with invalid length",
218 std::make_error_code(std::errc::invalid_argument));
219 Obj.
Length =
static_cast<size_t>(endian::read<T, Endianness>(Current));
220 Current +=
sizeof(
T);
225 if (
sizeof(
T) > remainingSpace())
226 return make_error<StringError>(
227 "Invalid Ext with invalid length",
228 std::make_error_code(std::errc::invalid_argument));
229 T Size = endian::read<T, Endianness>(Current);
230 Current +=
sizeof(
T);
231 return createExt(Obj,
Size);
235 if (
Size > remainingSpace())
236 return make_error<StringError>(
237 "Invalid Raw with insufficient payload",
238 std::make_error_code(std::errc::invalid_argument));
246 return make_error<StringError>(
247 "Invalid Ext with no type",
248 std::make_error_code(std::errc::invalid_argument));
250 if (
Size > remainingSpace())
251 return make_error<StringError>(
252 "Invalid Ext with insufficient payload",
253 std::make_error_code(std::errc::invalid_argument));
This file contains constants used for implementing MessagePack support.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
Reads MessagePack objects from memory, one at a time.
Reader(MemoryBufferRef InputBuffer)
Construct a reader, keeping a reference to the InputBuffer.
Expected< bool > read(Object &Obj)
Read one object from the input buffer, advancing past it.
This is an optimization pass for GlobalISel generic memory operations.
int8_t Type
User-defined extension type.
StringRef Bytes
Raw bytes of the extension object.
MessagePack object, represented as a tagged union of C++ types.
int64_t Int
Value for Type::Int.
double Float
Value for Type::Float.
StringRef Raw
Value for Type::String and Type::Binary.
uint64_t UInt
Value for Type::Uint.
bool Bool
Value for Type::Boolean.
ExtensionType Extension
Value for Type::Extension.
size_t Length
Value for Type::Array and Type::Map.