mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 02:09:29 +01:00
VarInt patch by "bake3978", taken from https://code.google.com/p/bitcoinj/issues/detail?id=582
Deleted unnecessary codes; long val; ... val = first; ... this.value = val; -> this.value = first;
This commit is contained in:
parent
98cc6adfc2
commit
0af58eb9bb
@ -34,25 +34,23 @@ public class VarInt {
|
||||
// Bitcoin has its own varint format, known in the C++ source as "compact size".
|
||||
public VarInt(byte[] buf, int offset) {
|
||||
int first = 0xFF & buf[offset];
|
||||
long val;
|
||||
if (first < 253) {
|
||||
// 8 bits.
|
||||
val = first;
|
||||
this.value = first;
|
||||
originallyEncodedSize = 1;
|
||||
} else if (first == 253) {
|
||||
// 16 bits.
|
||||
val = (0xFF & buf[offset + 1]) | ((0xFF & buf[offset + 2]) << 8);
|
||||
this.value = (0xFF & buf[offset + 1]) | ((0xFF & buf[offset + 2]) << 8);
|
||||
originallyEncodedSize = 3;
|
||||
} else if (first == 254) {
|
||||
// 32 bits.
|
||||
val = Utils.readUint32(buf, offset + 1);
|
||||
this.value = Utils.readUint32(buf, offset + 1);
|
||||
originallyEncodedSize = 5;
|
||||
} else {
|
||||
// 64 bits.
|
||||
val = Utils.readUint32(buf, offset + 1) | (Utils.readUint32(buf, offset + 5) << 32);
|
||||
this.value = Utils.readUint32(buf, offset + 1) | (Utils.readUint32(buf, offset + 5) << 32);
|
||||
originallyEncodedSize = 9;
|
||||
}
|
||||
this.value = val;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user