Mercurial > stress-tester
changeset 717:e38dee41176b
LongVLC
author | Devel 1 |
---|---|
date | Wed, 29 Nov 2017 16:55:08 +0100 |
parents | 751516d6b33f |
children | 4c0a80deaa95 |
files | stress-tester/src/main/java/com/passus/st/reader/nc/NcDataHelper.java stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java |
diffstat | 2 files changed, 20 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataHelper.java Wed Nov 29 16:09:15 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataHelper.java Wed Nov 29 16:55:08 2017 +0100 @@ -160,21 +160,23 @@ } public int getLongVLC(byte[] data, int startIndex, int endIndex, MutableLong length) { + long value; + int readed; int b1 = data[startIndex++] & 0xFF; - int b2 = data[startIndex++] & 0xFF; - long value = (b1 << 8) + b2; - int readed = 2; - - if ((value & VLC_LONG_TRESHOLD) != 0) { - value &= ~VLC_LONG_TRESHOLD; - if (value == 0 || value > 8) { - throw new IllegalArgumentException("Invalid length byte value " + value + "."); - } else if (endIndex - startIndex < value) { + if ((b1 & VLC_INT_TRESHOLD) != 0) { + b1 &= ~VLC_INT_TRESHOLD; + readed = 1; + if (b1 == 0 || b1 > 8) { + throw new IllegalArgumentException("Invalid length byte value " + b1 + "."); + } else if (endIndex - startIndex < b1) { throw new IndexOutOfBoundsException(); } - - readed += value; - value = DataUtils.getLong(data, startIndex, (int) value); + value = DataUtils.getLong(data, startIndex, (int) b1); + readed = b1 + 1; + } else { + int b2 = data[startIndex++] & 0xFF; + readed = 2; + value = (b1 << 8) + b2; } length.setValue(value); @@ -221,14 +223,13 @@ return 2; } else { int bytes = DataUtils.countBytes(value); - if (endIndex - startIndex < bytes + 2) { + if (endIndex - startIndex < bytes + 1) { throw new IndexOutOfBoundsException(); } - data[startIndex++] = (byte) 0x80; - data[startIndex++] = (byte) bytes; + data[startIndex++] = (byte) (0x80 | bytes); DataUtils.putLong(data, startIndex, bytes, value); - return bytes + 2; + return bytes + 1; } }
--- a/stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java Wed Nov 29 16:09:15 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java Wed Nov 29 16:55:08 2017 +0100 @@ -43,8 +43,9 @@ {new byte[]{0x01, 0x00}, 2, 0x0100L}, {new byte[]{0x01, B_FF}, 2, 0x01ffL}, {new byte[]{0x7F, B_FF}, 2, 0x7fffL}, - {new byte[]{B_80, 0x02, B_80, B_80}, 4, 0x8080L}, - {new byte[]{B_80, 0x02, B_FF, B_FF}, 4, 0xffffL} + {new byte[]{(byte) 0x82, B_80, 0x00}, 3, 0x8000L}, + {new byte[]{(byte) 0x82, B_80, B_80}, 3, 0x8080L}, + {new byte[]{(byte) 0x82, B_FF, B_FF}, 3, 0xffffL} }; }