MsgPack.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef LLVM_BINARYFORMAT_MSGPACK_H
  14. #define LLVM_BINARYFORMAT_MSGPACK_H
  15. #include "llvm/Support/DataTypes.h"
  16. #include "llvm/Support/Endian.h"
  17. namespace llvm {
  18. namespace msgpack {
  19. /// The endianness of all multi-byte encoded values in MessagePack.
  20. constexpr support::endianness Endianness = support::big;
  21. /// The first byte identifiers of MessagePack object formats.
  22. namespace FirstByte {
  23. #define HANDLE_MP_FIRST_BYTE(ID, NAME) constexpr uint8_t NAME = ID;
  24. #include "llvm/BinaryFormat/MsgPack.def"
  25. }
  26. /// Most significant bits used to identify "Fix" variants in MessagePack.
  27. ///
  28. /// For example, FixStr objects encode their size in the five least significant
  29. /// bits of their first byte, which is identified by the bit pattern "101" in
  30. /// the three most significant bits. So FixBits::String contains 0b10100000.
  31. ///
  32. /// A corresponding mask of the bit pattern is found in \c FixBitsMask.
  33. namespace FixBits {
  34. #define HANDLE_MP_FIX_BITS(ID, NAME) constexpr uint8_t NAME = ID;
  35. #include "llvm/BinaryFormat/MsgPack.def"
  36. }
  37. /// Mask of bits used to identify "Fix" variants in MessagePack.
  38. ///
  39. /// For example, FixStr objects encode their size in the five least significant
  40. /// bits of their first byte, which is identified by the bit pattern "101" in
  41. /// the three most significant bits. So FixBitsMask::String contains
  42. /// 0b11100000.
  43. ///
  44. /// The corresponding bit pattern to mask for is found in FixBits.
  45. namespace FixBitsMask {
  46. #define HANDLE_MP_FIX_BITS_MASK(ID, NAME) constexpr uint8_t NAME = ID;
  47. #include "llvm/BinaryFormat/MsgPack.def"
  48. }
  49. /// The maximum value or size encodable in "Fix" variants of formats.
  50. ///
  51. /// For example, FixStr objects encode their size in the five least significant
  52. /// bits of their first byte, so the largest encodable size is 0b00011111.
  53. namespace FixMax {
  54. #define HANDLE_MP_FIX_MAX(ID, NAME) constexpr uint8_t NAME = ID;
  55. #include "llvm/BinaryFormat/MsgPack.def"
  56. }
  57. /// The exact size encodable in "Fix" variants of formats.
  58. ///
  59. /// The only objects for which an exact size makes sense are of Extension type.
  60. ///
  61. /// For example, FixExt4 stores an extension type containing exactly four bytes.
  62. namespace FixLen {
  63. #define HANDLE_MP_FIX_LEN(ID, NAME) constexpr uint8_t NAME = ID;
  64. #include "llvm/BinaryFormat/MsgPack.def"
  65. }
  66. /// The minimum value or size encodable in "Fix" variants of formats.
  67. ///
  68. /// The only object for which a minimum makes sense is a negative FixNum.
  69. ///
  70. /// Negative FixNum objects encode their signed integer value in one byte, but
  71. /// they must have the pattern "111" as their three most significant bits. This
  72. /// means all values are negative, and the smallest representable value is
  73. /// 0b11100000.
  74. namespace FixMin {
  75. #define HANDLE_MP_FIX_MIN(ID, NAME) constexpr int8_t NAME = ID;
  76. #include "llvm/BinaryFormat/MsgPack.def"
  77. }
  78. } // end namespace msgpack
  79. } // end namespace llvm
  80. #endif // LLVM_BINARYFORMAT_MSGPACK_H