8000 vpack: fixed ObjectIterator · anderick/arangodb-java-driver@bc48945 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc48945

Browse files
author
Mark
committed
vpack: fixed ObjectIterator
1 parent 7329c66 commit bc48945

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/main/java/com/arangodb/velocypack/util/ObjectIterator.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ public ObjectIterator(final VPackSlice slice) throws VPackValueTypeException {
2121
throw new VPackValueTypeException(ValueType.OBJECT);
2222
}
2323
if (size > 0) {
24-
final byte head = slice.head();
25-
if (head == 0x14) {
26-
current = slice.keyAt(0).getStart();
27-
}
24+
current = slice.keyAt(0).getStart();
2825
}
2926
}
3027

src/test/java/com/arangodb/velocypack/VPackSliceTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,21 @@ public void arrayIterator() throws VPackException {
862862
}
863863
}
864864

865+
@Test
866+
public void objectIterator() throws VPackException {
867+
// {"a":"test","b":"test","c":"test"}
868+
final String[] fields = new String[] { "a", "b", "c" };
869+
final VPackSlice slice = new VPackSlice(new byte[] { 0x0b, 0x1b, 0x03, 0x41, 0x61, 0x44, 0x74, 0x65, 0x73, 0x74,
870+
0x41, 0x62, 0x44, 0x74, 0x65, 0x73, 0x74, 0x41, 0x63, 0x44, 0x74, 0x65, 0x73, 0x74, 0x03, 0x0a, 0x11 });
871+
int i = 0;
872+
for (final Iterator<VPackSlice> iterator = slice.iterator(); iterator.hasNext();) {
873+
final VPackSlice next = iterator.next();
874+
Assert.assertEquals(fields[i++], next.getAsString());
875+
final VPackSlice v = new VPackSlice(next.getVpack(), next.getStart() + next.getByteSize());
876+
Assert.assertEquals("test", v.getAsString());
877+
}
878+
}
879+
865880
@Test(expected = VPackValueTypeException.class)
866881
public void nonArrayNonObjectIterator() {
867882
final VPackSlice vpack = new VPackSlice(new byte[] { 0x1a });

0 commit comments

Comments
 (0)
0