edgeport - v1.0.3
    Preparing search index...

    Function encodeRemainingLength

    • Encodes an MQTT remaining-length value as a 1-4 byte varint.

      MQTT uses a base-128 varint with the high bit of each byte signalling continuation, capping the value at MAX_REMAINING_LENGTH. This is the length prefix on every fixed header and is the most error-prone part of the wire format, so it lives in its own well-tested function.

      Parameters

      Returns Uint8Array

      The encoded bytes (1-4 of them).

      If value is negative or exceeds the maximum.

      1.0.0

      import { encodeRemainingLength } from 'edgeport/mqtt';

      encodeRemainingLength(0); // Uint8Array [0x00]
      encodeRemainingLength(127); // Uint8Array [0x7f]
      encodeRemainingLength(128); // Uint8Array [0x80, 0x01]