Class BSV::Wallet::Wire::Reader ¶
Inherits: Object
Reader reads sequentially from a binary string.
Public Instance Methods¶
initialize(data) ¶
- @param
data[String] binary data - @return [Reader] a new instance of Reader
next_negative_one?() ¶
Whether the next varint is the NegativeOne sentinel (0xFFFF…). Peeks at the next byte without consuming it. - @return [Boolean]
peek_byte() ¶
Look at the next byte without consuming it. - @raise [ArgumentError] - @return [Integer]
read_base64_int() ¶
Read a binary value and return it Base64-encoded. - @return [String] Base64-encoded string
read_byte() ¶
Read a single byte. - @raise [ArgumentError] - @return [Integer]
read_bytes(n) ¶
Read n raw bytes. - @raise [ArgumentError] - @return [String] binary string
read_int_bytes() ¶
Read a varint-length-prefixed byte array (ReadIntBytes in Go). - @return [String] binary string
read_optional_bool() ¶
Read an optional boolean byte (Go/BRC-103 convention). 0xFF → nil, 0x00 → false, 0x01 → true - @return [Boolean, nil]
read_optional_bytes_with_flag(fixed_size: = nil) ¶
Read optional bytes with a 1-byte flag prefix (Go BytesOptionWithFlag). 0x00 → nil; 0x01 → read varint_len + bytes (or fixed_size bytes). - @param fixed_size [Integer, nil] if set, read exactly this many bytes (no varint) - @return [String, nil] binary string or nil
read_optional_string() ¶
Read an optional string: NegativeOne sentinel → nil; else varint len + bytes. - @return [String, nil]
read_optional_uint32() ¶
Read an optional uint32: NegativeOne sentinel → nil; else varint → Integer. - @return [Integer, nil]
read_outpoint() ¶
Read an outpoint: 32-byte display-order txid + varint vout. - @return [Hash] { txid_hex: String, vout: Integer }
read_privileged_params() ¶
Read privileged params (Go decodePrivilegedParams). - @return [Array(Boolean|nil, String|nil)]
read_remaining() ¶
Read all remaining bytes. - @return [String] binary string
read_satoshis() ¶
Read 8-byte little-endian uint64 satoshi amount. - @return [Integer]
read_str_with_varint_len() ¶
Read a varint-prefixed UTF-8 string. - @raise [ArgumentError] if the bytes are not valid UTF-8 - @return [String]
read_string() ¶
Read a varint-len string (always present, 0-length = empty string). Matches Go ReadString which returns "" for length 0 or NegativeOne. - @return [String]
read_string_map() ¶
Read a string map: varint count + key/value pairs (each varint-len-prefixed). - @return [Hash
read_string_slice() ¶
Read an array of strings encoded as varint count + each optional string. NegativeOne sentinel count → nil. - @return [Array
read_txid_slice() ¶
Read a txid slice: NegativeOne → nil; else varint count + 32 bytes per txid. Go stores txids in wire order (txID) — returned as hex without reversal. - @return [Array
read_varint() ¶
Read a Bitcoin varint. - @return [Integer]
remaining() ¶
Remaining bytes.