forked from msgpack/msgpack-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUnpackerSkip.java
More file actions
83 lines (69 loc) · 2.98 KB
/
TestUnpackerSkip.java
File metadata and controls
83 lines (69 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.msgpack.unpacker;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.msgpack.MessagePack;
import org.msgpack.packer.BufferPacker;
import org.msgpack.unpacker.BufferUnpacker;
import org.msgpack.type.Value;
import org.msgpack.type.ValueFactory;
public class TestUnpackerSkip {
@Test
public void testPrimitive() throws Exception {
MessagePack msgpack = new MessagePack();
BufferPacker packer = msgpack.createBufferPacker();
for (int i = 0; i < 10; i++) {
packer.write(1);
packer.write(i);
}
byte[] bytes = packer.toByteArray();
BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
for (int i = 0; i < 10; i++) {
unpacker.skip();
int n = unpacker.readInt();
assertEquals(i, n);
}
}
@Test
public void testNested() throws Exception {
MessagePack msgpack = new MessagePack();
BufferPacker packer = msgpack.createBufferPacker();
Value v1 = ValueFactory.createArrayValue(new Value[] {
ValueFactory.createRawValue("a"),
ValueFactory.createMapValue(new Value[] {
ValueFactory.createRawValue("k1"),
ValueFactory
.createArrayValue(new Value[] { ValueFactory
.createIntegerValue(1) }) }) });
Value v2 = ValueFactory.createArrayValue(new Value[] {
ValueFactory.createMapValue(new Value[] {
ValueFactory.createRawValue("k1"),
ValueFactory
.createArrayValue(new Value[] { ValueFactory
.createIntegerValue(1) }),
ValueFactory.createRawValue("k2"),
ValueFactory
.createArrayValue(new Value[] { ValueFactory
.createIntegerValue(2) }) }),
ValueFactory.createMapValue(new Value[] {
ValueFactory.createRawValue("k1"),
ValueFactory
.createArrayValue(new Value[] { ValueFactory
.createIntegerValue(1) }),
ValueFactory.createRawValue("k2"),
ValueFactory
.createArrayValue(new Value[] { ValueFactory
.createIntegerValue(2) }) }),
ValueFactory.createRawValue("a") });
for (int i = 0; i < 10; i++) {
packer.write(v1);
packer.write(v2);
}
byte[] bytes = packer.toByteArray();
BufferUnpacker unpacker = msgpack.createBufferUnpacker(bytes);
for (int i = 0; i < 10; i++) {
unpacker.skip();
Value v2a = unpacker.readValue();
assertEquals(v2, v2a);
}
}
}