xref: /llvm-project/llvm/include/llvm/BinaryFormat/MsgPack.h (revision 4a0ccfa865437fe29ef2ecb18152df7694dddb7f)
120f9cd88SScott Linder //===-- MsgPack.h - MessagePack Constants -----------------------*- C++ -*-===//
220f9cd88SScott Linder //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
620f9cd88SScott Linder //
720f9cd88SScott Linder //===----------------------------------------------------------------------===//
820f9cd88SScott Linder ///
920f9cd88SScott Linder /// \file
1020f9cd88SScott Linder /// This file contains constants used for implementing MessagePack support.
1120f9cd88SScott Linder ///
1220f9cd88SScott Linder //===----------------------------------------------------------------------===//
1320f9cd88SScott Linder 
1420f9cd88SScott Linder #ifndef LLVM_BINARYFORMAT_MSGPACK_H
1520f9cd88SScott Linder #define LLVM_BINARYFORMAT_MSGPACK_H
1620f9cd88SScott Linder 
1720f9cd88SScott Linder #include "llvm/Support/DataTypes.h"
1820f9cd88SScott Linder #include "llvm/Support/Endian.h"
1920f9cd88SScott Linder 
2020f9cd88SScott Linder namespace llvm {
2120f9cd88SScott Linder namespace msgpack {
2220f9cd88SScott Linder 
2320f9cd88SScott Linder /// The endianness of all multi-byte encoded values in MessagePack.
24*4a0ccfa8SKazu Hirata constexpr llvm::endianness Endianness = llvm::endianness::big;
2520f9cd88SScott Linder 
2620f9cd88SScott Linder /// The first byte identifiers of MessagePack object formats.
2720f9cd88SScott Linder namespace FirstByte {
2820f9cd88SScott Linder #define HANDLE_MP_FIRST_BYTE(ID, NAME) constexpr uint8_t NAME = ID;
2920f9cd88SScott Linder #include "llvm/BinaryFormat/MsgPack.def"
3020f9cd88SScott Linder }
3120f9cd88SScott Linder 
3220f9cd88SScott Linder /// Most significant bits used to identify "Fix" variants in MessagePack.
3320f9cd88SScott Linder ///
3420f9cd88SScott Linder /// For example, FixStr objects encode their size in the five least significant
3520f9cd88SScott Linder /// bits of their first byte, which is identified by the bit pattern "101" in
3620f9cd88SScott Linder /// the three most significant bits. So FixBits::String contains 0b10100000.
3720f9cd88SScott Linder ///
3820f9cd88SScott Linder /// A corresponding mask of the bit pattern is found in \c FixBitsMask.
3920f9cd88SScott Linder namespace FixBits {
4020f9cd88SScott Linder #define HANDLE_MP_FIX_BITS(ID, NAME) constexpr uint8_t NAME = ID;
4120f9cd88SScott Linder #include "llvm/BinaryFormat/MsgPack.def"
4220f9cd88SScott Linder }
4320f9cd88SScott Linder 
4420f9cd88SScott Linder /// Mask of bits used to identify "Fix" variants in MessagePack.
4520f9cd88SScott Linder ///
4620f9cd88SScott Linder /// For example, FixStr objects encode their size in the five least significant
4720f9cd88SScott Linder /// bits of their first byte, which is identified by the bit pattern "101" in
4820f9cd88SScott Linder /// the three most significant bits. So FixBitsMask::String contains
4920f9cd88SScott Linder /// 0b11100000.
5020f9cd88SScott Linder ///
5120f9cd88SScott Linder /// The corresponding bit pattern to mask for is found in FixBits.
5220f9cd88SScott Linder namespace FixBitsMask {
5320f9cd88SScott Linder #define HANDLE_MP_FIX_BITS_MASK(ID, NAME) constexpr uint8_t NAME = ID;
5420f9cd88SScott Linder #include "llvm/BinaryFormat/MsgPack.def"
5520f9cd88SScott Linder }
5620f9cd88SScott Linder 
5720f9cd88SScott Linder /// The maximum value or size encodable in "Fix" variants of formats.
5820f9cd88SScott Linder ///
5920f9cd88SScott Linder /// For example, FixStr objects encode their size in the five least significant
6020f9cd88SScott Linder /// bits of their first byte, so the largest encodable size is 0b00011111.
6120f9cd88SScott Linder namespace FixMax {
6220f9cd88SScott Linder #define HANDLE_MP_FIX_MAX(ID, NAME) constexpr uint8_t NAME = ID;
6320f9cd88SScott Linder #include "llvm/BinaryFormat/MsgPack.def"
6420f9cd88SScott Linder }
6520f9cd88SScott Linder 
6620f9cd88SScott Linder /// The exact size encodable in "Fix" variants of formats.
6720f9cd88SScott Linder ///
6820f9cd88SScott Linder /// The only objects for which an exact size makes sense are of Extension type.
6920f9cd88SScott Linder ///
7020f9cd88SScott Linder /// For example, FixExt4 stores an extension type containing exactly four bytes.
7120f9cd88SScott Linder namespace FixLen {
7220f9cd88SScott Linder #define HANDLE_MP_FIX_LEN(ID, NAME) constexpr uint8_t NAME = ID;
7320f9cd88SScott Linder #include "llvm/BinaryFormat/MsgPack.def"
7420f9cd88SScott Linder }
7520f9cd88SScott Linder 
7620f9cd88SScott Linder /// The minimum value or size encodable in "Fix" variants of formats.
7720f9cd88SScott Linder ///
7820f9cd88SScott Linder /// The only object for which a minimum makes sense is a negative FixNum.
7920f9cd88SScott Linder ///
8020f9cd88SScott Linder /// Negative FixNum objects encode their signed integer value in one byte, but
8120f9cd88SScott Linder /// they must have the pattern "111" as their three most significant bits. This
8220f9cd88SScott Linder /// means all values are negative, and the smallest representable value is
8320f9cd88SScott Linder /// 0b11100000.
8420f9cd88SScott Linder namespace FixMin {
8520f9cd88SScott Linder #define HANDLE_MP_FIX_MIN(ID, NAME) constexpr int8_t NAME = ID;
8620f9cd88SScott Linder #include "llvm/BinaryFormat/MsgPack.def"
8720f9cd88SScott Linder }
8820f9cd88SScott Linder 
8920f9cd88SScott Linder } // end namespace msgpack
9020f9cd88SScott Linder } // end namespace llvm
9120f9cd88SScott Linder 
9220f9cd88SScott Linder #endif // LLVM_BINARYFORMAT_MSGPACK_H
93