Class BSV::Wallet::Wire::Reader ¶
Inherits: Object
Consumes a binary byte string using BRC-100 wire protocol decoding conventions.
All multi-byte integers use little-endian order unless stated otherwise. VarInts follow Bitcoin encoding; the 9-byte MaxUint64 sentinel decodes as -1.
Constants¶
MAX_UINT64 ¶
The 64-bit sentinel value that encodes -1 in a signed VarInt.
Attributes¶
offset [R] ¶
Current read position (bytes consumed so far).
Public Instance Methods¶
initialize(data) ¶
- @return [Reader] a new instance of Reader
read_byte() ¶
Reads a single unsigned byte (0–255). - @return [Integer]
read_byte_array() ¶
Reads a VarInt-prefixed byte array. - @return [String] binary string
read_bytes(n) ¶
Reads exactly n raw bytes. - @param n [Integer] - @return [String] binary string
read_counterparty() ¶
Reads a counterparty value using the first-byte dispatch scheme. - @return [String, nil] 'self', 'anyone', nil, or 66-char hex pubkey
read_int8() ¶
Reads a signed 8-bit integer (-128–127). - @return [Integer]
read_map() ¶
Reads an optional string→string map: VarInt count + key/value pairs, or nil. - @return [Hash, nil]
read_optional_bool() ¶
Reads a signed Int8 optional boolean: 1=true, 0=false, -1=nil. - @return [Boolean, nil]
read_optional_byte_array() ¶
Reads an optional VarInt-prefixed byte array; returns nil for the -1 sentinel. - @return [String, nil]
read_optional_utf8_string() ¶
Reads an optional VarInt-prefixed UTF-8 string; returns nil for the -1 sentinel. - @return [String, nil]
read_outpoint() ¶
Reads an outpoint: 32 bytes (txid hex in display order) + VarInt index. - @return [Array(String, Integer)] [txid_hex, index]
read_privileged() ¶
Reads privileged parameters: optional bool + Int8-length reason string. - @return [Array(Boolean|nil, String|nil)] [privileged, privileged_reason]
read_protocol_id() ¶
Reads a protocol ID: UInt8 security level + VarInt-prefixed UTF-8 name. - @return [Array(Integer, String)] [level, name]
read_remaining() ¶
Reads all remaining bytes from the current offset. - @return [String] binary string
read_signed_varint() ¶
Reads a signed VarInt, returning -1 for the MaxUint64 sentinel. - @return [Integer] non-negative value or -1
read_string_array() ¶
Reads an optional string array: VarInt count + strings, or nil for the -1 sentinel. - @return [Array
read_utf8_string() ¶
Reads a VarInt-prefixed UTF-8 string. - @return [String]
read_varint() ¶
Reads an unsigned Bitcoin VarInt. - @return [Integer]