mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
VarInt: get rid of code duplication in deprecated constructor
This commit is contained in:
parent
b528fb5180
commit
b4abf7d794
1 changed files with 3 additions and 14 deletions
|
@ -96,20 +96,9 @@ public class VarInt {
|
||||||
/** @deprecated use {@link #ofBytes(byte[], int)} */
|
/** @deprecated use {@link #ofBytes(byte[], int)} */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public VarInt(byte[] buf, int offset) {
|
public VarInt(byte[] buf, int offset) {
|
||||||
int first = 0xFF & buf[offset];
|
VarInt copy = read(ByteBuffer.wrap(buf, offset, buf.length));
|
||||||
if (first < 253) {
|
value = copy.value;
|
||||||
value = first;
|
originallyEncodedSize = copy.originallyEncodedSize;
|
||||||
originallyEncodedSize = 1; // 1 data byte (8 bits)
|
|
||||||
} else if (first == 253) {
|
|
||||||
value = ByteUtils.readUint16(buf, offset + 1);
|
|
||||||
originallyEncodedSize = 3; // 1 marker + 2 data bytes (16 bits)
|
|
||||||
} else if (first == 254) {
|
|
||||||
value = ByteUtils.readUint32(buf, offset + 1);
|
|
||||||
originallyEncodedSize = 5; // 1 marker + 4 data bytes (32 bits)
|
|
||||||
} else {
|
|
||||||
value = ByteUtils.readInt64(buf, offset + 1);
|
|
||||||
originallyEncodedSize = 9; // 1 marker + 8 data bytes (64 bits)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long longValue() {
|
public long longValue() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue