Skip to content

Commit c77fd0d

Browse files
committed
bugfix byte size of custom types
1 parent a9f036b commit c77fd0d

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,11 @@ private int getByteSize(int start) {
531531
size = getByteSize(start + offset) + offset;
532532
break;
533533
case CUSTOM:
534-
if (head == 0xf4 || head == 0xf5 || head == 0xf6) {
534+
if (head == (byte) 0xf4 || head == (byte) 0xf5 || head == (byte) 0xf6) {
535535
size = 2 + NumberUtil.toLong(vpack, start + 1, 1);
536-
} else if (head == 0xf7 || head == 0xf8 || head == 0xf9) {
536+
} else if (head == (byte) 0xf7 || head == (byte) 0xf8 || head == (byte) 0xf9) {
537537
size = 3 + NumberUtil.toLong(vpack, start + 1, 2);
538-
} else if (head == 0xfa || head == 0xfb || head == 0xfc) {
538+
} else if (head == (byte) 0xfa || head == (byte) 0xfb || head == (byte) 0xfc) {
539539
size = 5 + NumberUtil.toLong(vpack, start + 1, 4);
540540
} else /* if (head == 0xfd || head == 0xfe || head == 0xff) */ {
541541
size = 9 + NumberUtil.toLong(vpack, start + 1, 8);

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
package com.arangodb.velocypack;
2222

23-
import static org.hamcrest.Matchers.is;
24-
import static org.junit.Assert.*;
23+
import com.arangodb.velocypack.exception.VPackException;
24+
import com.arangodb.velocypack.exception.VPackValueTypeException;
25+
import org.junit.Test;
2526

2627
import java.math.BigInteger;
2728
import java.util.Arrays;
@@ -30,10 +31,8 @@
3031
import java.util.Iterator;
3132
import java.util.Map.Entry;
3233

33-
import org.junit.Test;
34-
35-
import com.arangodb.velocypack.exception.VPackException;
36-
import com.arangodb.velocypack.exception.VPackValueTypeException;
34+
import static org.hamcrest.Matchers.is;
35+
import static org.junit.Assert.*;
3736

3837
/**
3938
* @author Mark Vollmary
@@ -401,27 +400,28 @@ private void checkBCD(final byte[] vpack) {
401400

402401
@Test
403402
public void isCustom() {
404-
checkCustom(new byte[] { (byte) 0xf0 });
405-
checkCustom(new byte[] { (byte) 0xf1 });
406-
checkCustom(new byte[] { (byte) 0xf2 });
407-
checkCustom(new byte[] { (byte) 0xf3 });
408-
checkCustom(new byte[] { (byte) 0xf4 });
409-
checkCustom(new byte[] { (byte) 0xf5 });
410-
checkCustom(new byte[] { (byte) 0xf6 });
411-
checkCustom(new byte[] { (byte) 0xf7 });
412-
checkCustom(new byte[] { (byte) 0xf8 });
413-
checkCustom(new byte[] { (byte) 0xf9 });
414-
checkCustom(new byte[] { (byte) 0xfa });
415-
checkCustom(new byte[] { (byte) 0xfb });
416-
checkCustom(new byte[] { (byte) 0xfc });
417-
checkCustom(new byte[] { (byte) 0xfd });
418-
checkCustom(new byte[] { (byte) 0xfe });
419-
checkCustom(new byte[] { (byte) 0xff });
420-
}
421-
422-
private void checkCustom(final byte[] vpack) {
403+
checkCustom(new byte[] { (byte) 0xf0 }, 2);
404+
checkCustom(new byte[] { (byte) 0xf1 }, 3);
405+
checkCustom(new byte[] { (byte) 0xf2 }, 5);
406+
checkCustom(new byte[] { (byte) 0xf3 }, 9);
407+
checkCustom(new byte[] { (byte) 0xf4, (byte) 0x00 }, 2);
408+
checkCustom(new byte[] { (byte) 0xf5, (byte) 0x01 }, 3);
409+
checkCustom(new byte[] { (byte) 0xf6, (byte) 0x02 }, 4);
410+
checkCustom(new byte[] { (byte) 0xf7, (byte) 0x00, (byte) 0x00 }, 3);
411+
checkCustom(new byte[] { (byte) 0xf8, (byte) 0x01, (byte) 0x00 }, 4);
412+
checkCustom(new byte[] { (byte) 0xf9, (byte) 0x02, (byte) 0x00 }, 5);
413+
checkCustom(new byte[] { (byte) 0xfa, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 5);
414+
checkCustom(new byte[] { (byte) 0xfb, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 6);
415+
checkCustom(new byte[] { (byte) 0xfc, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 7);
416+
checkCustom(new byte[] { (byte) 0xfd, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 9);
417+
checkCustom(new byte[] { (byte) 0xfe, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 10);
418+
checkCustom(new byte[] { (byte) 0xff, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 11);
419+
}
420+
421+
private void checkCustom(final byte[] vpack, final int expectedSize) {
423422
final VPackSlice slice = new VPackSlice(vpack);
424423
assertThat(slice.isCustom(), is(true));
424+
assertThat(slice.getByteSize(), is(expectedSize));
425425
}
426426

427427
@Test

0 commit comments

Comments
 (0)