Methods
decode(packet) → {number|false}
Decodes a received packet.
Parameters:
Name | Type | Description |
---|---|---|
packet |
Uint8Array | The packet to decode. The packet should include the 8-byte header (messageBytes, blockId). |
- Source:
Throws:
-
If the packet's message size does not match the initialized message size.
- Type
- Error
Returns:
The result of the decode operation (e.g., Wirehair_Success, Wirehair_NeedMore).
Returns `false` if the blockId has already been received.
- Type
- number | false
init(messageBytes, packetSizeWithHeaders)
Initializes the decoder with the total message size and packet size.
This method must be called before decoding any packets if not using `initFromPacket`.
Parameters:
Name | Type | Description |
---|---|---|
messageBytes |
number | The total size of the original message in bytes. |
packetSizeWithHeaders |
number | The size of each packet, including headers (typically 8 bytes). The actual data payload size per packet will be this value minus 8 bytes. |
- Source:
Throws:
-
If WASM buffer allocation for packet data fails.
- Type
- Error
initFromPacket(packet)
Initializes the decoder based on information from the first received packet.
This is a convenience method that calls `init` with parameters extracted from the packet.
Parameters:
Name | Type | Description |
---|---|---|
packet |
Uint8Array | The first packet received for the message. It's used to determine message size and packet size. |
- Source:
(async, static) create() → {Promise.<WirehairDecoder>}
Asynchronously creates and initializes a WirehairDecoder instance.
Ensures the Wirehair WebAssembly module is initialized before creating the decoder.
- Source:
Returns:
A promise that resolves to a new WirehairDecoder instance.
- Type
- Promise.<WirehairDecoder>