Skip to content

Commit 885790f

Browse files
committed
bugfix byte size of BCD
1 parent c77fd0d commit 885790f

File tree

3 files changed

+33
-39
lines changed

3 files changed

+33
-39
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
- fixed custom types byte size
10+
- fixed BCD byte size
911
- Map and Set VPackInstanceCreators preserve collections entries order (based on `LinkedHashSet` and `LinkedHashMap`)
1012

1113
## [2.1.0] - 2019-12-20

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,19 @@
2020

2121
package com.arangodb.velocypack;
2222

23-
import java.io.Serializable;
24-
import java.math.BigDecimal;
25-
import java.math.BigInteger;
26-
import java.nio.charset.StandardCharsets;
27-
import java.util.ArrayList;
28-
import java.util.Collections;
29-
import java.util.Date;
30-
import java.util.Iterator;
31-
import java.util.List;
32-
import java.util.Map.Entry;
33-
3423
import com.arangodb.velocypack.exception.VPackException;
3524
import com.arangodb.velocypack.exception.VPackKeyTypeException;
3625
import com.arangodb.velocypack.exception.VPackNeedAttributeTranslatorException;
3726
import com.arangodb.velocypack.exception.VPackValueTypeException;
3827
import com.arangodb.velocypack.internal.VPackAttributeTranslatorImpl;
39-
import com.arangodb.velocypack.internal.util.BinaryUtil;
40-
import com.arangodb.velocypack.internal.util.DateUtil;
41-
import com.arangodb.velocypack.internal.util.NumberUtil;
42-
import com.arangodb.velocypack.internal.util.ObjectArrayUtil;
43-
import com.arangodb.velocypack.internal.util.ValueLengthUtil;
44-
import com.arangodb.velocypack.internal.util.ValueTypeUtil;
28+
import com.arangodb.velocypack.internal.util.*;
29+
30+
import java.io.Serializable;
31+
import java.math.BigDecimal;
32+
import java.math.BigInteger;
33+
import java.nio.charset.StandardCharsets;
34+
import java.util.*;
35+
import java.util.Map.Entry;
4536

4637
/**
4738
* @author Mark Vollmary
@@ -520,10 +511,10 @@ private int getByteSize(int start) {
520511
size = 1 + head - ((byte) 0xbf) + NumberUtil.toLong(vpack, start + 1, head - ((byte) 0xbf));
521512
break;
522513
case BCD:
523-
if (head <= 0xcf) {
524-
size = 1 + head + ((byte) 0xc7) + NumberUtil.toLong(vpack, start + 1, head - ((byte) 0xc7));
514+
if (head <= (byte) 0xcf) {
515+
size = 1 + head - ((byte) 0xc7) + NumberUtil.toLong(vpack, start + 1, head - ((byte) 0xc7)) + 4;
525516
} else {
526-
size = 1 + head - ((byte) 0xcf) + NumberUtil.toLong(vpack, start + 1, head - ((byte) 0xcf));
517+
size = 1 + head - ((byte) 0xcf) + NumberUtil.toLong(vpack, start + 1, head - ((byte) 0xcf)) + 4;
527518
}
528519
break;
529520
case TAGGED:

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -375,27 +375,28 @@ private void checkBinary(final byte[] vpack) {
375375

376376
@Test
377377
public void isBCD() {
378-
checkBCD(new byte[] { (byte) 0xc8 });
379-
checkBCD(new byte[] { (byte) 0xc9 });
380-
checkBCD(new byte[] { (byte) 0xca });
381-
checkBCD(new byte[] { (byte) 0xcb });
382-
checkBCD(new byte[] { (byte) 0xcc });
383-
checkBCD(new byte[] { (byte) 0xcd });
384-
checkBCD(new byte[] { (byte) 0xce });
385-
checkBCD(new byte[] { (byte) 0xcf });
386-
checkBCD(new byte[] { (byte) 0xd0 });
387-
checkBCD(new byte[] { (byte) 0xd1 });
388-
checkBCD(new byte[] { (byte) 0xd2 });
389-
checkBCD(new byte[] { (byte) 0xd3 });
390-
checkBCD(new byte[] { (byte) 0xd4 });
391-
checkBCD(new byte[] { (byte) 0xd5 });
392-
checkBCD(new byte[] { (byte) 0xd6 });
393-
checkBCD(new byte[] { (byte) 0xd7 });
394-
}
395-
396-
private void checkBCD(final byte[] vpack) {
378+
checkBCD(new byte[] { (byte) 0xc8, (byte) 0x03 }, 9);
379+
checkBCD(new byte[] { (byte) 0xc9, (byte) 0x03, (byte) 0x00 }, 10);
380+
checkBCD(new byte[] { (byte) 0xca, (byte) 0x03, (byte) 0x00, (byte) 0x00 }, 11);
381+
checkBCD(new byte[] { (byte) 0xcb, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 12);
382+
checkBCD(new byte[] { (byte) 0xcc, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 13);
383+
checkBCD(new byte[] { (byte) 0xcd, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 14);
384+
checkBCD(new byte[] { (byte) 0xce, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 15);
385+
checkBCD(new byte[] { (byte) 0xcf, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 16);
386+
checkBCD(new byte[] { (byte) 0xd0, (byte) 0x03 }, 9);
387+
checkBCD(new byte[] { (byte) 0xd1, (byte) 0x03, (byte) 0x00 }, 10);
388+
checkBCD(new byte[] { (byte) 0xd2, (byte) 0x03, (byte) 0x00, (byte) 0x00 }, 11);
389+
checkBCD(new byte[] { (byte) 0xd3, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 12);
390+
checkBCD(new byte[] { (byte) 0xd4, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 13);
391+
checkBCD(new byte[] { (byte) 0xd5, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 14);
392+
checkBCD(new byte[] { (byte) 0xd6, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 15);
393+
checkBCD(new byte[] { (byte) 0xd7, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }, 16);
394+
}
395+
396+
private void checkBCD(final byte[] vpack, final int expectedSize) {
397397
final VPackSlice slice = new VPackSlice(vpack);
398398
assertThat(slice.isBCD(), is(true));
399+
assertThat(slice.getByteSize(), is(expectedSize));
399400
}
400401

401402
@Test

0 commit comments

Comments
 (0)