MsgPack.h 3.5 KB

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