类 VarInt
- java.lang.Object
-
- network.nerve.core.basic.VarInt
-
public class VarInt extends Object
A variable-length encoded unsigned integer using Satoshi's encoding (a.k.a. "CompactSize").
-
-
字段概要
字段 修饰符和类型 字段 说明 longvalue
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 byte[]encode()Encodes the value into its minimal representation.intgetOriginalSizeInBytes()Returns the original number of bytes used to encode the value if it was deserialized from a byte array, or the minimum encoded size if it was not.intgetSizeInBytes()Returns the minimum encoded size of the value.static intsizeOf(long value)Returns the minimum encoded size of the given unsigned long value.
-
-
-
构造器详细资料
-
VarInt
public VarInt(long value)
Constructs a new VarInt with the given unsigned long value.- 参数:
value- the unsigned long value (beware widening conversion of negatives!)
-
VarInt
public VarInt(byte[] buf, int offset)Constructs a new VarInt with the value parsed from the specified offset of the given buffer.- 参数:
buf- the buffer containing the valueoffset- the offset of the value
-
-
方法详细资料
-
getOriginalSizeInBytes
public int getOriginalSizeInBytes()
Returns the original number of bytes used to encode the value if it was deserialized from a byte array, or the minimum encoded size if it was not.
-
getSizeInBytes
public final int getSizeInBytes()
Returns the minimum encoded size of the value.
-
sizeOf
public static int sizeOf(long value)
Returns the minimum encoded size of the given unsigned long value.- 参数:
value- the unsigned long value (beware widening conversion of negatives!)
-
encode
public byte[] encode()
Encodes the value into its minimal representation.- 返回:
- the minimal encoded bytes of the value
-
-