Skip to content

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.

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 - @return [String] encoded binary bytes