|
15 | 15 | // |
16 | 16 | package org.msgpack.core; |
17 | 17 |
|
18 | | -import org.msgpack.core.MessagePack.Code; |
19 | 18 | import org.msgpack.core.annotations.VisibleForTesting; |
20 | 19 | import org.msgpack.value.ValueType; |
21 | 20 |
|
@@ -66,6 +65,94 @@ public enum MessageFormat |
66 | 65 | MAP32(ValueType.MAP), |
67 | 66 | NEGFIXINT(ValueType.INTEGER); |
68 | 67 |
|
| 68 | + /** |
| 69 | + * The prefix code set of MessagePack. See also https://github.com/msgpack/msgpack/blob/master/spec.md for details. |
| 70 | + */ |
| 71 | + public static final class Code |
| 72 | + { |
| 73 | + public static final boolean isFixInt(byte b) |
| 74 | + { |
| 75 | + int v = b & 0xFF; |
| 76 | + return v <= 0x7f || v >= 0xe0; |
| 77 | + } |
| 78 | + |
| 79 | + public static final boolean isPosFixInt(byte b) |
| 80 | + { |
| 81 | + return (b & POSFIXINT_MASK) == 0; |
| 82 | + } |
| 83 | + |
| 84 | + public static final boolean isNegFixInt(byte b) |
| 85 | + { |
| 86 | + return (b & NEGFIXINT_PREFIX) == NEGFIXINT_PREFIX; |
| 87 | + } |
| 88 | + |
| 89 | + public static final boolean isFixStr(byte b) |
| 90 | + { |
| 91 | + return (b & (byte) 0xe0) == Code.FIXSTR_PREFIX; |
| 92 | + } |
| 93 | + |
| 94 | + public static final boolean isFixedArray(byte b) |
| 95 | + { |
| 96 | + return (b & (byte) 0xf0) == Code.FIXARRAY_PREFIX; |
| 97 | + } |
| 98 | + |
| 99 | + public static final boolean isFixedMap(byte b) |
| 100 | + { |
| 101 | + return (b & (byte) 0xe0) == Code.FIXMAP_PREFIX; |
| 102 | + } |
| 103 | + |
| 104 | + public static final boolean isFixedRaw(byte b) |
| 105 | + { |
| 106 | + return (b & (byte) 0xe0) == Code.FIXSTR_PREFIX; |
| 107 | + } |
| 108 | + |
| 109 | + public static final byte POSFIXINT_MASK = (byte) 0x80; |
| 110 | + |
| 111 | + public static final byte FIXMAP_PREFIX = (byte) 0x80; |
| 112 | + public static final byte FIXARRAY_PREFIX = (byte) 0x90; |
| 113 | + public static final byte FIXSTR_PREFIX = (byte) 0xa0; |
| 114 | + |
| 115 | + public static final byte NIL = (byte) 0xc0; |
| 116 | + public static final byte NEVER_USED = (byte) 0xc1; |
| 117 | + public static final byte FALSE = (byte) 0xc2; |
| 118 | + public static final byte TRUE = (byte) 0xc3; |
| 119 | + public static final byte BIN8 = (byte) 0xc4; |
| 120 | + public static final byte BIN16 = (byte) 0xc5; |
| 121 | + public static final byte BIN32 = (byte) 0xc6; |
| 122 | + public static final byte EXT8 = (byte) 0xc7; |
| 123 | + public static final byte EXT16 = (byte) 0xc8; |
| 124 | + public static final byte EXT32 = (byte) 0xc9; |
| 125 | + public static final byte FLOAT32 = (byte) 0xca; |
| 126 | + public static final byte FLOAT64 = (byte) 0xcb; |
| 127 | + public static final byte UINT8 = (byte) 0xcc; |
| 128 | + public static final byte UINT16 = (byte) 0xcd; |
| 129 | + public static final byte UINT32 = (byte) 0xce; |
| 130 | + public static final byte UINT64 = (byte) 0xcf; |
| 131 | + |
| 132 | + public static final byte INT8 = (byte) 0xd0; |
| 133 | + public static final byte INT16 = (byte) 0xd1; |
| 134 | + public static final byte INT32 = (byte) 0xd2; |
| 135 | + public static final byte INT64 = (byte) 0xd3; |
| 136 | + |
| 137 | + public static final byte FIXEXT1 = (byte) 0xd4; |
| 138 | + public static final byte FIXEXT2 = (byte) 0xd5; |
| 139 | + public static final byte FIXEXT4 = (byte) 0xd6; |
| 140 | + public static final byte FIXEXT8 = (byte) 0xd7; |
| 141 | + public static final byte FIXEXT16 = (byte) 0xd8; |
| 142 | + |
| 143 | + public static final byte STR8 = (byte) 0xd9; |
| 144 | + public static final byte STR16 = (byte) 0xda; |
| 145 | + public static final byte STR32 = (byte) 0xdb; |
| 146 | + |
| 147 | + public static final byte ARRAY16 = (byte) 0xdc; |
| 148 | + public static final byte ARRAY32 = (byte) 0xdd; |
| 149 | + |
| 150 | + public static final byte MAP16 = (byte) 0xde; |
| 151 | + public static final byte MAP32 = (byte) 0xdf; |
| 152 | + |
| 153 | + public static final byte NEGFIXINT_PREFIX = (byte) 0xe0; |
| 154 | + } |
| 155 | + |
69 | 156 | private static final MessageFormat[] formatTable = new MessageFormat[256]; |
70 | 157 | private final ValueType valueType; |
71 | 158 |
|
|
0 commit comments