Skip to content

Commit 9560b0a

Browse files
author
Mark
committed
fixed VPack parsing (issue #80)
1 parent b436976 commit 9560b0a

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
v4.1.4 (2016-11-xx)
22
---------------------------
33
* added VPack serializer/de-serializer for java.util.UUID
4+
* fixed VPack parsing (issue #80)
45

56
v4.1.3 (2016-11-22)
67
---------------------------

src/main/java/com/arangodb/velocypack/VPackBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ protected VPackBuilder close(final boolean sort)
721721
final int offsetSize;
722722
// can be 1, 2, 4 or 8 for the byte width of the offsets,
723723
// the byte length and the number of subvalues:
724-
if ((size - 1 - tos) + in.size() - 6 <= 0xff) {
724+
if (size - tos + in.size() - 6 <= 0xff) {
725725
// We have so far used _pos - tos bytes, including the reserved 8
726726
// bytes for byte length and number of subvalues. In the 1-byte
727727
// number

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,4 +911,25 @@ public void addBitInteger() {
911911
assertThat(vpack.getAsBigInteger(), is(value));
912912
}
913913

914+
@Test
915+
public void objectWithByteSize256() {
916+
final StringBuilder aa = new StringBuilder();
917+
final int stringLength = 231;
918+
for (int i = 0; i < stringLength; ++i) {
919+
aa.append("a");
920+
}
921+
final String foo = "foo";
922+
final String bar1 = "bar1";
923+
final String bar2 = "bar2";
924+
final VPackSlice vpack = new VPackBuilder().add(ValueType.OBJECT).add(foo, ValueType.OBJECT).add(bar2, "")
925+
.add(bar1, aa.toString()).close().close().slice();
926+
927+
assertThat(vpack.isObject(), is(true));
928+
assertThat(vpack.get(foo).isObject(), is(true));
929+
assertThat(vpack.get(foo).get(bar1).isString(), is(true));
930+
assertThat(vpack.get(foo).get(bar1).getLength(), is(stringLength));
931+
assertThat(vpack.get(foo).get(bar2).isString(), is(true));
932+
assertThat(vpack.get(foo).get(bar2).getLength(), is(0));
933+
}
934+
914935
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.velocypack;
22+
23+
/**
24+
* @author Mark - mark at arangodb.com
25+
*
26+
*/
27+
public class VPackUtil {
28+
29+
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
30+
31+
public static String toHex(final VPackSlice vpack) {
32+
final byte[] bytes = vpack.getRawVPack();
33+
final char[] hexChars = new char[bytes.length * 2];
34+
for (int j = 0; j < bytes.length; j++) {
35+
final int v = bytes[j] & 0xFF;
36+
hexChars[j * 2] = hexArray[v >>> 4];
37+
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
38+
}
39+
return new String(hexChars).replaceAll("(.{32})", "$1\n").replaceAll("(.{2})", "0x$1 ").toLowerCase();
40+
}
41+
42+
}

0 commit comments

Comments
 (0)