Module BSV::Transaction::VarInt ¶
Bitcoin variable-length integer encoding/decoding.
VarInts encode unsigned integers compactly: values under 253 use a single byte; larger values use a marker byte followed by 2, 4, or 8 bytes in little-endian order.
Constants¶
MAX_UINT64 ¶
Maximum value representable by a Bitcoin VarInt (unsigned 64-bit).
Public Class Methods¶
decode(data, offset = 0) ¶
Decode a Bitcoin VarInt from binary data at the given offset. - @param data [String] binary data containing the VarInt - @param offset [Integer] byte offset to start reading from - @raise [ArgumentError] - @return [Array(Integer, Integer)] the decoded value and number of bytes consumed
encode(value) ¶
Encode an integer as a Bitcoin VarInt. - @param value [Integer] non-negative integer to encode (0..2^64-1) - @raise [ArgumentError] if +value+ is negative or exceeds 2^64-1 - @return [String] encoded binary bytes