@tgsnake/skema
    Preparing search index...

    Function bigintToBuffer

    • Converts a JS native bigint value into a Node.js Buffer with custom byte-padding, endianness, and sign representation.

      Parameters

      • int: bigint

        The bigint value to serialize into the buffer.

      • padding: number

        The absolute target size of the output buffer in bytes.

      • litte: boolean = true

        Set to true for little-endian encoding; set to false for big-endian. Defaults to true.

      • signed: boolean = false

        Set to true to allow signed integers and two's complement representation. Defaults to false.

      Returns Buffer

      A new Buffer representation of the bigint value.

      This utility handles both signed and unsigned numeric translations. For signed negative bigints, it computes the manual two's complement transformation in either little-endian or big-endian formats to match Telegram MTProto specifications.

      If the bigint requires more bytes to represent than the specified padding size.

      If the bigint is negative and signed is set to false.

      // Unsigned little-endian 4-byte padding
      const buf = bigintToBuffer(BigInt(42), 4, true, false);