@squawk
    Preparing search index...

    Function deframeBeastBytes

    • Deframes as many complete Beast frames as are present in buffer, unescaping 0x1a 0x1a byte-stuffing and decoding each message via @squawk/mode-s. Pure and stateless - safe to call repeatedly as more bytes arrive, as long as the caller prepends the previous call's remainder to the next chunk (a frame routinely arrives split across two calls when fed from a live socket).

      import { deframeBeastBytes } from '@squawk/beast';

      let pending = new Uint8Array(0);
      function onChunk(chunk: Uint8Array): void {
      const combined = new Uint8Array(pending.length + chunk.length);
      combined.set(pending);
      combined.set(chunk, pending.length);
      const result = deframeBeastBytes(combined);
      pending = result.remainder;
      for (const frame of result.frames) {
      console.log(frame.type, frame.decoded);
      }
      }

      Parameters

      • buffer: Uint8Array

        Raw bytes from a Beast feed, possibly including a partial frame left over from a previous call.

      Returns DeframeResult

      The frames and errors found, plus any trailing incomplete frame.