Skip to content

Commit f7d57e3

Browse files
committed
Relocate Code class inside MessagePack again since it is used for Packer/Unpacker, which do not need to depend on MessageFormat enum
1 parent d29276f commit f7d57e3

File tree

7 files changed

+134
-130
lines changed

7 files changed

+134
-130
lines changed

msgpack-core/src/main/java/org/msgpack/core/MessageFormat.java

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.msgpack.core.annotations.VisibleForTesting;
1919
import org.msgpack.value.ValueType;
20+
import org.msgpack.core.MessagePack.Code;
2021

2122
/**
2223
* Describes the list of the message format types defined in the MessagePack specification.
@@ -65,94 +66,6 @@ public enum MessageFormat
6566
MAP32(ValueType.MAP),
6667
NEGFIXINT(ValueType.INTEGER);
6768

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) 0xf0) == 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-
15669
private static final MessageFormat[] formatTable = new MessageFormat[256];
15770
private final ValueType valueType;
15871

msgpack-core/src/main/java/org/msgpack/core/MessagePack.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,95 @@ public class MessagePack
3737
{
3838
public static final Charset UTF8 = Charset.forName("UTF-8");
3939

40+
/**
41+
* The prefix code set of MessagePack. See also https://github.com/msgpack/msgpack/blob/master/spec.md for details.
42+
*/
43+
public static final class Code
44+
{
45+
public static final boolean isFixInt(byte b)
46+
{
47+
int v = b & 0xFF;
48+
return v <= 0x7f || v >= 0xe0;
49+
}
50+
51+
public static final boolean isPosFixInt(byte b)
52+
{
53+
return (b & POSFIXINT_MASK) == 0;
54+
}
55+
56+
public static final boolean isNegFixInt(byte b)
57+
{
58+
return (b & NEGFIXINT_PREFIX) == NEGFIXINT_PREFIX;
59+
}
60+
61+
public static final boolean isFixStr(byte b)
62+
{
63+
return (b & (byte) 0xe0) == Code.FIXSTR_PREFIX;
64+
}
65+
66+
public static final boolean isFixedArray(byte b)
67+
{
68+
return (b & (byte) 0xf0) == Code.FIXARRAY_PREFIX;
69+
}
70+
71+
public static final boolean isFixedMap(byte b)
72+
{
73+
return (b & (byte) 0xf0) == Code.FIXMAP_PREFIX;
74+
}
75+
76+
public static final boolean isFixedRaw(byte b)
77+
{
78+
return (b & (byte) 0xe0) == Code.FIXSTR_PREFIX;
79+
}
80+
81+
public static final byte POSFIXINT_MASK = (byte) 0x80;
82+
83+
public static final byte FIXMAP_PREFIX = (byte) 0x80;
84+
public static final byte FIXARRAY_PREFIX = (byte) 0x90;
85+
public static final byte FIXSTR_PREFIX = (byte) 0xa0;
86+
87+
public static final byte NIL = (byte) 0xc0;
88+
public static final byte NEVER_USED = (byte) 0xc1;
89+
public static final byte FALSE = (byte) 0xc2;
90+
public static final byte TRUE = (byte) 0xc3;
91+
public static final byte BIN8 = (byte) 0xc4;
92+
public static final byte BIN16 = (byte) 0xc5;
93+
public static final byte BIN32 = (byte) 0xc6;
94+
public static final byte EXT8 = (byte) 0xc7;
95+
public static final byte EXT16 = (byte) 0xc8;
96+
public static final byte EXT32 = (byte) 0xc9;
97+
public static final byte FLOAT32 = (byte) 0xca;
98+
public static final byte FLOAT64 = (byte) 0xcb;
99+
public static final byte UINT8 = (byte) 0xcc;
100+
public static final byte UINT16 = (byte) 0xcd;
101+
public static final byte UINT32 = (byte) 0xce;
102+
public static final byte UINT64 = (byte) 0xcf;
103+
104+
public static final byte INT8 = (byte) 0xd0;
105+
public static final byte INT16 = (byte) 0xd1;
106+
public static final byte INT32 = (byte) 0xd2;
107+
public static final byte INT64 = (byte) 0xd3;
108+
109+
public static final byte FIXEXT1 = (byte) 0xd4;
110+
public static final byte FIXEXT2 = (byte) 0xd5;
111+
public static final byte FIXEXT4 = (byte) 0xd6;
112+
public static final byte FIXEXT8 = (byte) 0xd7;
113+
public static final byte FIXEXT16 = (byte) 0xd8;
114+
115+
public static final byte STR8 = (byte) 0xd9;
116+
public static final byte STR16 = (byte) 0xda;
117+
public static final byte STR32 = (byte) 0xdb;
118+
119+
public static final byte ARRAY16 = (byte) 0xdc;
120+
public static final byte ARRAY32 = (byte) 0xdd;
121+
122+
public static final byte MAP16 = (byte) 0xde;
123+
public static final byte MAP32 = (byte) 0xdf;
124+
125+
public static final byte NEGFIXINT_PREFIX = (byte) 0xe0;
126+
}
127+
128+
40129
private MessagePack()
41130
{
42131
// Prohibit instantiation of this class

msgpack-core/src/main/java/org/msgpack/core/MessagePacker.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,40 @@
2828
import java.nio.charset.CharsetEncoder;
2929
import java.nio.charset.CoderResult;
3030

31-
import static org.msgpack.core.MessageFormat.Code.ARRAY16;
32-
import static org.msgpack.core.MessageFormat.Code.ARRAY32;
33-
import static org.msgpack.core.MessageFormat.Code.BIN16;
34-
import static org.msgpack.core.MessageFormat.Code.BIN32;
35-
import static org.msgpack.core.MessageFormat.Code.BIN8;
36-
import static org.msgpack.core.MessageFormat.Code.EXT16;
37-
import static org.msgpack.core.MessageFormat.Code.EXT32;
38-
import static org.msgpack.core.MessageFormat.Code.EXT8;
39-
import static org.msgpack.core.MessageFormat.Code.FALSE;
40-
import static org.msgpack.core.MessageFormat.Code.FIXARRAY_PREFIX;
41-
import static org.msgpack.core.MessageFormat.Code.FIXEXT1;
42-
import static org.msgpack.core.MessageFormat.Code.FIXEXT16;
43-
import static org.msgpack.core.MessageFormat.Code.FIXEXT2;
44-
import static org.msgpack.core.MessageFormat.Code.FIXEXT4;
45-
import static org.msgpack.core.MessageFormat.Code.FIXEXT8;
46-
import static org.msgpack.core.MessageFormat.Code.FIXMAP_PREFIX;
47-
import static org.msgpack.core.MessageFormat.Code.FIXSTR_PREFIX;
48-
import static org.msgpack.core.MessageFormat.Code.FLOAT32;
49-
import static org.msgpack.core.MessageFormat.Code.FLOAT64;
50-
import static org.msgpack.core.MessageFormat.Code.INT16;
51-
import static org.msgpack.core.MessageFormat.Code.INT32;
52-
import static org.msgpack.core.MessageFormat.Code.INT64;
53-
import static org.msgpack.core.MessageFormat.Code.INT8;
54-
import static org.msgpack.core.MessageFormat.Code.MAP16;
55-
import static org.msgpack.core.MessageFormat.Code.MAP32;
56-
import static org.msgpack.core.MessageFormat.Code.NIL;
57-
import static org.msgpack.core.MessageFormat.Code.STR16;
58-
import static org.msgpack.core.MessageFormat.Code.STR32;
59-
import static org.msgpack.core.MessageFormat.Code.STR8;
60-
import static org.msgpack.core.MessageFormat.Code.TRUE;
61-
import static org.msgpack.core.MessageFormat.Code.UINT16;
62-
import static org.msgpack.core.MessageFormat.Code.UINT32;
63-
import static org.msgpack.core.MessageFormat.Code.UINT64;
64-
import static org.msgpack.core.MessageFormat.Code.UINT8;
31+
import static org.msgpack.core.MessagePack.Code.ARRAY16;
32+
import static org.msgpack.core.MessagePack.Code.ARRAY32;
33+
import static org.msgpack.core.MessagePack.Code.BIN16;
34+
import static org.msgpack.core.MessagePack.Code.BIN32;
35+
import static org.msgpack.core.MessagePack.Code.BIN8;
36+
import static org.msgpack.core.MessagePack.Code.EXT16;
37+
import static org.msgpack.core.MessagePack.Code.EXT32;
38+
import static org.msgpack.core.MessagePack.Code.EXT8;
39+
import static org.msgpack.core.MessagePack.Code.FALSE;
40+
import static org.msgpack.core.MessagePack.Code.FIXARRAY_PREFIX;
41+
import static org.msgpack.core.MessagePack.Code.FIXEXT1;
42+
import static org.msgpack.core.MessagePack.Code.FIXEXT16;
43+
import static org.msgpack.core.MessagePack.Code.FIXEXT2;
44+
import static org.msgpack.core.MessagePack.Code.FIXEXT4;
45+
import static org.msgpack.core.MessagePack.Code.FIXEXT8;
46+
import static org.msgpack.core.MessagePack.Code.FIXMAP_PREFIX;
47+
import static org.msgpack.core.MessagePack.Code.FIXSTR_PREFIX;
48+
import static org.msgpack.core.MessagePack.Code.FLOAT32;
49+
import static org.msgpack.core.MessagePack.Code.FLOAT64;
50+
import static org.msgpack.core.MessagePack.Code.INT16;
51+
import static org.msgpack.core.MessagePack.Code.INT32;
52+
import static org.msgpack.core.MessagePack.Code.INT64;
53+
import static org.msgpack.core.MessagePack.Code.INT8;
54+
import static org.msgpack.core.MessagePack.Code.MAP16;
55+
import static org.msgpack.core.MessagePack.Code.MAP32;
56+
import static org.msgpack.core.MessagePack.Code.NIL;
57+
import static org.msgpack.core.MessagePack.Code.STR16;
58+
import static org.msgpack.core.MessagePack.Code.STR32;
59+
import static org.msgpack.core.MessagePack.Code.STR8;
60+
import static org.msgpack.core.MessagePack.Code.TRUE;
61+
import static org.msgpack.core.MessagePack.Code.UINT16;
62+
import static org.msgpack.core.MessagePack.Code.UINT32;
63+
import static org.msgpack.core.MessagePack.Code.UINT64;
64+
import static org.msgpack.core.MessagePack.Code.UINT8;
6565
import static org.msgpack.core.Preconditions.checkNotNull;
6666

6767
/**

msgpack-core/src/main/java/org/msgpack/core/MessageUnpacker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616
package org.msgpack.core;
1717

18-
import org.msgpack.core.MessageFormat.Code;
18+
import org.msgpack.core.MessagePack.Code;
1919
import org.msgpack.core.buffer.MessageBuffer;
2020
import org.msgpack.core.buffer.MessageBufferInput;
2121
import org.msgpack.value.ImmutableValue;

msgpack-core/src/test/scala/org/msgpack/core/MessageFormatTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616
package org.msgpack.core
1717

18-
import org.msgpack.core.MessageFormat.Code
18+
import org.msgpack.core.MessagePack.Code
1919
import org.msgpack.value.ValueType
2020
import org.scalatest.exceptions.TestFailedException
2121

msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import java.math.BigInteger
2020
import java.nio.CharBuffer
2121
import java.nio.charset.{CodingErrorAction, UnmappableCharacterException}
2222

23-
import org.msgpack.core.MessageFormat.Code
23+
import org.msgpack.core.MessagePack.Code
2424
import org.msgpack.core.MessagePack.{UnpackerConfig, PackerConfig}
2525
import org.msgpack.value.{Value, Variable}
2626

msgpack-core/src/test/scala/org/msgpack/value/ValueTypeTest.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
//
1616
package org.msgpack.value
1717

18-
import org.msgpack.core.MessageFormat.Code._
18+
import org.msgpack.core.MessagePack.Code._
1919
import org.msgpack.core.{MessageFormat, MessageFormatException, MessagePackSpec}
2020

2121
/**
22-
* Created on 2014/05/06.
23-
*/
22+
* Created on 2014/05/06.
23+
*/
2424
class ValueTypeTest
25-
extends MessagePackSpec {
25+
extends MessagePackSpec
26+
{
2627

2728
"ValueType" should {
2829

2930
"lookup ValueType from a byte value" taggedAs ("code") in {
3031

31-
def check(b: Byte, tpe: ValueType) {
32+
def check(b: Byte, tpe: ValueType)
33+
{
3234
MessageFormat.valueOf(b).getValueType shouldBe tpe
3335
}
3436

0 commit comments

Comments
 (0)