1 //===-- MsgPack.h - MessagePack Constants -----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains constants used for implementing MessagePack support.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_BINARYFORMAT_MSGPACK_H
15 #define LLVM_BINARYFORMAT_MSGPACK_H
16 
17 #include "llvm/Support/DataTypes.h"
18 #include "llvm/Support/Endian.h"
19 
20 namespace llvm {
21 namespace msgpack {
22 
23 /// The endianness of all multi-byte encoded values in MessagePack.
24 constexpr support::endianness Endianness = support::big;
25 
26 /// The first byte identifiers of MessagePack object formats.
27 namespace FirstByte {
28 #define HANDLE_MP_FIRST_BYTE(ID, NAME) constexpr uint8_t NAME = ID;
29 #include "llvm/BinaryFormat/MsgPack.def"
30 }
31 
32 /// Most significant bits used to identify "Fix" variants in MessagePack.
33 ///
34 /// For example, FixStr objects encode their size in the five least significant
35 /// bits of their first byte, which is identified by the bit pattern "101" in
36 /// the three most significant bits. So FixBits::String contains 0b10100000.
37 ///
38 /// A corresponding mask of the bit pattern is found in \c FixBitsMask.
39 namespace FixBits {
40 #define HANDLE_MP_FIX_BITS(ID, NAME) constexpr uint8_t NAME = ID;
41 #include "llvm/BinaryFormat/MsgPack.def"
42 }
43 
44 /// Mask of bits used to identify "Fix" variants in MessagePack.
45 ///
46 /// For example, FixStr objects encode their size in the five least significant
47 /// bits of their first byte, which is identified by the bit pattern "101" in
48 /// the three most significant bits. So FixBitsMask::String contains
49 /// 0b11100000.
50 ///
51 /// The corresponding bit pattern to mask for is found in FixBits.
52 namespace FixBitsMask {
53 #define HANDLE_MP_FIX_BITS_MASK(ID, NAME) constexpr uint8_t NAME = ID;
54 #include "llvm/BinaryFormat/MsgPack.def"
55 }
56 
57 /// The maximum value or size encodable in "Fix" variants of formats.
58 ///
59 /// For example, FixStr objects encode their size in the five least significant
60 /// bits of their first byte, so the largest encodable size is 0b00011111.
61 namespace FixMax {
62 #define HANDLE_MP_FIX_MAX(ID, NAME) constexpr uint8_t NAME = ID;
63 #include "llvm/BinaryFormat/MsgPack.def"
64 }
65 
66 /// The exact size encodable in "Fix" variants of formats.
67 ///
68 /// The only objects for which an exact size makes sense are of Extension type.
69 ///
70 /// For example, FixExt4 stores an extension type containing exactly four bytes.
71 namespace FixLen {
72 #define HANDLE_MP_FIX_LEN(ID, NAME) constexpr uint8_t NAME = ID;
73 #include "llvm/BinaryFormat/MsgPack.def"
74 }
75 
76 /// The minimum value or size encodable in "Fix" variants of formats.
77 ///
78 /// The only object for which a minimum makes sense is a negative FixNum.
79 ///
80 /// Negative FixNum objects encode their signed integer value in one byte, but
81 /// they must have the pattern "111" as their three most significant bits. This
82 /// means all values are negative, and the smallest representable value is
83 /// 0b11100000.
84 namespace FixMin {
85 #define HANDLE_MP_FIX_MIN(ID, NAME) constexpr int8_t NAME = ID;
86 #include "llvm/BinaryFormat/MsgPack.def"
87 }
88 
89 } // end namespace msgpack
90 } // end namespace llvm
91 
92 #endif // LLVM_BINARYFORMAT_MSGPACK_H
93