@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
53 lines • 2.72 kB
TypeScript
/**
* Send a logical payload through a callback, splitting into fragment
* packets if it exceeds the channel's single-packet capacity.
*
* Layout of each emitted fragment packet (before the Channel adds its
* 8-byte header):
*
* uint8 FRAGMENT_PACKET_TYPE
* uint16 message_id (little-endian)
* uint8 chunk_index
* uint8 total_chunks
* bytes chunk_payload
*
* The chunk_payload bytes are slices of the original logical payload,
* concatenated in chunk_index order they reconstruct the original
* payload byte-for-byte. The logical payload's own packet-type byte is
* the first byte of chunk 0 and is preserved by the reassembly.
*
* Single-packet messages (payload <= MAX_CHANNEL_PAYLOAD_BYTES) are sent
* as-is with NO fragmentation header — the receiver dispatches them
* normally via the FIRST byte. Fragmentation overhead only applies when
* the payload genuinely doesn't fit.
*
* @param {Uint8Array} payload
* @param {number} payload_length
* @param {number} message_id sender-assigned, unique per logical message
* @param {number} fragment_packet_type packet-type byte for fragment packets
* @param {Uint8Array} scratch reusable scratch buffer; must be >= MAX_CHANNEL_PAYLOAD_BYTES
* @param {function(Uint8Array, number): void} send_fn
* invoked once per emitted packet — single send for non-fragmented case,
* N sends for fragmented case
*/
export function send_fragmented(payload: Uint8Array, payload_length: number, message_id: number, fragment_packet_type: number, scratch: Uint8Array, send_fn: (arg0: Uint8Array, arg1: number) => void): void;
/**
* Re-emit a single fragment chunk for a previously-sent fragmented
* message. Used by the NACK retransmit path: the sender's
* {@link FragmentRetention} keeps the source bytes so any chunk can be
* deterministically rebuilt.
*
* The wire layout matches what {@link send_fragmented} would have
* produced for the same `(message_id, chunk_index, total_chunks)` —
* receivers can't tell a retransmit from an original.
*
* @param {Uint8Array} payload retained source bytes
* @param {number} payload_length
* @param {number} message_id
* @param {number} chunk_index must be < derived total_chunks; silently ignored otherwise
* @param {number} fragment_packet_type
* @param {Uint8Array} scratch reusable scratch; must be >= MAX_CHANNEL_PAYLOAD_BYTES
* @param {function(Uint8Array, number): void} send_fn
*/
export function resend_fragment_chunk(payload: Uint8Array, payload_length: number, message_id: number, chunk_index: number, fragment_packet_type: number, scratch: Uint8Array, send_fn: (arg0: Uint8Array, arg1: number) => void): void;
//# sourceMappingURL=fragment_send.d.ts.map