# Module BSV::Wallet::Wire::Frame <a id="module-BSV-Wallet-Wire-Frame"></a>

BRC-103 request and result frame codec.

Port of go-sdk/wallet/serializer/frame.go. Two frame types:

Request frame (client → wallet):
    [1 byte: call][1 byte: originator_len][originator_len bytes: UTF-8][remaining: params]

Result frame (wallet → client):
    [1 byte: error_code]
    On success (0x00): [remaining bytes: payload]
    On error (non-zero):
      [VarInt: message_len][message bytes]
      [VarInt: stack_len][stack bytes]

## Constants
### `MAX_ORIGINATOR_BYTES` <a id="constant-MAX_ORIGINATOR_BYTES"></a> <a id="MAX_ORIGINATOR_BYTES-constant"></a>
Maximum originator byte length enforced at write time. Matches the BRC-100
`OriginatorDomainNameStringUnder250Bytes` branded type used by
<code>Wire::Validation.originator_domain!</code>.

## Public Class Methods
### `decode_varint(data, offset = 0)` <a id="method-c-decode_varint"></a> <a id="decode_varint-class_method"></a>
- **@param** `data` [String] binary data
- **@param** `offset` [Integer] byte offset
- **@raise** [ArgumentError]
- **@return** [Array(Integer, Integer)] decoded value, bytes consumed

### `encode_varint(n)` <a id="method-c-encode_varint"></a> <a id="encode_varint-class_method"></a>
- **@param** `n` [Integer] unsigned integer
- **@return** [String] Bitcoin varint encoding

### `read_request(bytes)` <a id="method-c-read_request"></a> <a id="read_request-class_method"></a>
Decode a request frame.
- **@param** `bytes` [String] binary frame
- **@raise** [ArgumentError] if the frame is truncated or malformed
- **@return** [Hash] { call: Integer, originator: String, params: String }

### `read_result(bytes)` <a id="method-c-read_result"></a> <a id="read_result-class_method"></a>
Decode a result frame.
- **@param** `bytes` [String] binary frame
- **@raise** [BSV::Wallet::Error] the appropriate subclass on error
- **@raise** [ArgumentError] if the frame is truncated or malformed
- **@return** [String] binary payload on success

### `write_error(error:)` <a id="method-c-write_error"></a> <a id="write_error-class_method"></a>
Encode an error result frame.
- **@param** `error` [BSV::Wallet::Error] the error to encode
- **@return** [String] binary frame

### `write_request(call:, originator:, params: = nil)` <a id="method-c-write_request"></a> <a id="write_request-class_method"></a>
Encode a request frame.
- **@param** `call` [Integer] call byte (1..28)
- **@param** `originator` [String] originator domain (0..250 bytes UTF-8)
- **@param** `params` [String, nil] binary params payload
- **@raise** [ArgumentError] if originator exceeds 250 bytes
- **@return** [String] binary frame (ASCII-8BIT encoding)

### `write_result(payload: = nil)` <a id="method-c-write_result"></a> <a id="write_result-class_method"></a>
Encode a success result frame.
- **@param** `payload` [String, nil] binary payload
- **@return** [String] binary frame
