Class BSV::Wallet::Wire::Writer ¶
Inherits: Object
Writer accumulates bytes into a binary string buffer.
Attributes¶
buf [R] ¶
Returns the value of attribute buf.
Public Instance Methods¶
initialize() ¶
- @return [Writer] a new instance of Writer
write_byte(byte) ¶
Write a raw byte.
write_bytes(bytes) ¶
Write raw bytes (binary string).
write_int_bytes(bytes) ¶
Write a varint length-prefixed byte array (WriteIntBytes in Go). - @param bytes [String, nil] binary string; nil or empty → write varint 0
write_int_from_base64(base64_str) ¶
Write a binary value encoded as a Base64 string on the wire. Decodes the Base64 string and writes the raw bytes prefixed by varint length. - @param base64_str [String] standard Base64-encoded string
write_negative_one() ¶
Write the NegativeOne sentinel (MaxUint64 as a 9-byte varint: 9 × 0xFF). Used as a nil sentinel for optional fields in Go-compatible encoding.
write_optional_bool(value) ¶
Write an optional boolean as a single byte (Go/BRC-103 convention). nil → 0xFF, false → 0x00, true → 0x01
write_optional_bytes_with_flag(bytes, fixed_size: = nil) ¶
Write optional bytes with a 1-byte flag prefix (Go BytesOptionWithFlag). nil/empty → 0x00; else → 0x01 + varint_len + bytes (or fixed_size bytes). - @param bytes [String, nil] binary data - @param fixed_size [Integer, nil] if set, omit the varint length prefix
write_optional_string(str) ¶
Write an optional string: nil or empty → NegativeOne; else varint len + bytes. Matches Go WriteOptionalString. - @param str [String, nil]
write_optional_uint32(n) ¶
Write an optional uint32: nil → NegativeOne; else varint. - @param n [Integer, nil]
write_outpoint(txid_hex, vout) ¶
Write an outpoint: 32-byte display-order txid followed by varint vout.
Go encodeOutpoint calls WriteBytesReverse(Txid) which writes the wire-order (chainhash) bytes reversed — i.e. display order on the wire. The vout is a varint, not a fixed 4-byte LE integer. - @param txid_hex [String] 64-char display-order hex txid - @param vout [Integer] output index
write_privileged_params(privileged, reason) ¶
Write the privileged flag and reason (Go encodePrivilegedParams). privileged: nil → NegativeOneByte (0xFF), false → 0x00, true → 0x01. reason: nil or empty → NegativeOneByte; else varint len + bytes.
write_satoshis(n) ¶
Write a satoshi amount as 8-byte little-endian uint64.
write_str_with_varint_len(str) ¶
Write a UTF-8 string prefixed by its byte length as a varint.
write_string(str) ¶
Write a varint-len string (always present, 0-length for nil/empty). Matches Go WriteString which always writes the length prefix. - @param str [String, nil]
write_string_map(map) ¶
Write a string map (Hashmap [Hash, nil]
write_string_slice(arr) ¶
Write an array of strings: nil → NegativeOne; else varint count + each as optional string. Matches Go WriteStringSlice. - @param arr [Array
write_txid_slice(txids) ¶
Write a txid slice (array of 32-byte txids in wire order). nil → NegativeOne; else varint count + 32 raw bytes per txid. Txids are passed as 64-char display-order hex; written as-is (no byte reversal) to match Go WriteTxidSlice which writes txID (wire-order bytes directly). - @param txids [Array
write_varint(n) ¶
Write a Bitcoin varint.