@chickenjdk/byteutils
    Preparing search index...

    Class writableBufferBase<IsAsync>Abstract

    Type Parameters

    • IsAsync extends boolean = true | false

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    writeArrayBackwardsEndian:
        | ((...args: [value: number[]]) => MaybePromise)
        | ((...args: [value: number[]]) => MaybePromise) = ...

    Write data to the buffer backwards (writes data that was origionaly in LE format to the endianness of the buffer, I know that "backwards" is a little opinionated but the class was origionaly BE-only and I did not want to change too mutch)

    The data to write

    writeArrayEndian:
        | ((...args: [value: number[]]) => MaybePromise)
        | ((...args: [value: number[]]) => MaybePromise) = ...

    Write data to the buffer (writes data that was origionaly in BE format to the endianness of the buffer)

    The data to write

    writeUint8ArrayBackwardsEndian:
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => MaybePromise)
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => MaybePromise) = ...

    Write a Uint8Array to the buffer backwars (for the endian) Alias for .write because .write can handle Uint8Arrays. This exsists to have the similar naming of methods as readableBuffer's methods

    writeUint8ArrayEndian:
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => MaybePromise)
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => MaybePromise) = ...

    Write a Uint8Array to the buffer (for the endian) Alias for .write because .write can handle Uint8Arrays. This exsists to have the similar naming of methods as readableBuffer's methods

    Accessors

    • get isLe(): boolean

      If the buffer is little endian

      Returns boolean

    • set isLe(isLe: boolean): void

      If the buffer is little endian

      Parameters

      • isLe: boolean

      Returns void

    Methods

    • Calculate the minimum length of a signed integer in bytes. WARNING: No signed integers above 4278190079 or below -4278190079 (2^31 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeSignedIntegerBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent a signed integer in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. It subtracts this from 33 (equivilent to the number of bits in the signed integer +1 to account for the sign) to get the number of bits needed. The result is rounded up to the nearest byte.

    • Calculate the minimum length of a signed ones's complement in bytes. WARNING: No signed two's complements above 4278190079 or below -4278190079 (2^31 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeSignedOnesComplementBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent an signed one's in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. It subtracts this from 33 (equivilent to the number of bits in the signed one's complement +1 to account for the sign) to get the number of bits needed. The result is rounded up to the nearest byte.

    • Calculate the minimum length of a two's complement in bytes. WARNING: No two's complements above 4278190079 or below -4278190079 (2^31 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeTwosComplementBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent an two's complement in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. It subtracts this from 33 (equivilent to the number of bits in the two's complement +1 to account for the sign) to get the number of bits needed. The result is rounded up to the nearest byte.

    • Calculate the minimum length of an unsigned integer in bytes. WARNING: No unssigned ints above 4294967295 (2^32 - 1) are supported, so this will not work for those. This is due to the limitations of bitwise operators. You can write numbers higher than that via writeUnsignedIntBigint, but this function will not work for them.

      Parameters

      • value: number

        The value to check

      Returns number

      The calculated minimum length in bytes

      This function calculates the minimum number of bytes needed to represent an unsigned integer in binary format. It uses the Math.clz32 function to count the number of leading zeros in the binary representation of the value. The result is rounded up to the nearest byte.

    • Push a byte (numbers 0-255) to the buffer's end

      Parameters

      • value: number

        the byte to push

      Returns MaybePromise<void, IsAsync>

    • Write a array of bytes (numbers 0-255) to the buffer (first byte first written to the end[BE])

      Parameters

      • value: number[]

        The data to write

      Returns MaybePromise<void, IsAsync>

    • Write a array of bytes (numbers 0-255) to the buffer backwards (last byte first written to the end[LE])

      Parameters

      • value: number[]

      Returns MaybePromise<void, IsAsync>

    • Write a double float to the buffer

      Parameters

      • value: number

        The double float to write

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<8> : 8

      How many bytes were written (8)

    • Write a float to the buffer

      Parameters

      • value: number

        The float to write

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<4> : 4

      How many bytes were written (4)

    • Encode and write a signed integer

      Parameters

      • value: number

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns (
          MaybePromise<void, IsAsync> extends Promise<unknown>
              ? Promise<number>
              : number
      ) extends Promise<unknown>
          ? Promise<number>
          : number

      How many bytes were written (Same as bytes parameter if provided)

    • Encode and write a signed integer (from a bigint)

      Parameters

      • value: bigint

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns (
          MaybePromise<void, IsAsync> extends Promise<unknown>
              ? Promise<number>
              : number
      ) extends Promise<unknown>
          ? Promise<number>
          : number

      How many bytes were written (Same as bytes parameter)

    • Encode and write a signed integer (one byte)

      Parameters

      • value: number

        The number to encode

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<1> : 1

      How many bytes were written (1)

    • Encode and write signed integers (one byte)

      Parameters

      • values: number[]

        The numbers to encode

      Returns (MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<1> : 1) extends Promise<
          unknown,
      >
          ? Promise<number>
          : number

      How many bytes were written (Same as values.length)

    • Encode and write a signed one's complement

      Parameters

      • value: number

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns (
          MaybePromise<void, IsAsync> extends Promise<unknown>
              ? Promise<number>
              : number
      ) extends Promise<unknown>
          ? Promise<number>
          : number

      How many bytes were written (Same as bytes parameter if provided)

    • Encode and write a signed ones complement (from a bigint)

      Parameters

      • value: bigint

        The number to encode

      • bytes: number

        How many bytes to make the encoded value

      Returns (
          MaybePromise<void, IsAsync> extends Promise<unknown>
              ? Promise<number>
              : number
      ) extends Promise<unknown>
          ? Promise<number>
          : number

      How many bytes were written (Same as bytes parameter)

    • Encode and write a signed ones complement (one byte)

      Parameters

      • value: number

        The number to encode

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<1> : 1

      How many bytes were written (1)

    • Encode and write a signed ones complements

      Parameters

      • values: number[]

        The numbers to encode

      Returns (MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<1> : 1) extends Promise<
          unknown,
      >
          ? Promise<number>
          : number

      How many bytes were written (Same as values.length)

    • Write a utf8 string to the buffer

      Parameters

      • value: string
      • mutf8: boolean = false

        If true, write in java's mutf8 format instead. This was build for parsing java's .class files, so no complaining about it being a java-specific format.

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<number> : number

      How many bytes were written

    • Write a twos complement to the buffer

      Parameters

      • value: number

        The number to encode

      • bytes: number

        How long the twos complement to be written is in bytes

      Returns (
          MaybePromise<void, IsAsync> extends Promise<unknown>
              ? Promise<number>
              : number
      ) extends Promise<unknown>
          ? Promise<number>
          : number

      How many bytes were written (Same as bytes parameter if provided)

    • Write a twos complement to the buffer (From a bigint)

      Parameters

      • value: bigint

        The number to encode

      • bytes: number

        How long the twos complement to be written is in bytes

      Returns (
          MaybePromise<void, IsAsync> extends Promise<unknown>
              ? Promise<number>
              : number
      ) extends Promise<unknown>
          ? Promise<number>
          : number

      How many bytes were written (Same as bytes parameter)

    • Write a twos complement to the buffer (one byte)

      Parameters

      • value: number

        The number to encode

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<1> : 1

      How many bytes were written (1)

    • Write twos complements to the buffer (one byte each)

      Parameters

      • values: number[]

        The numbers to encode

      Returns (MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<1> : 1) extends Promise<
          unknown,
      >
          ? Promise<number>
          : number

      How many bytes were written (Same as values.length)

    • Write a Uint8Array to the buffer (first byte first written to the end[BE])

      Parameters

      • value: Uint8Array

      Returns MaybePromise<void, IsAsync>

    • Write a Uint8Array to the buffer backward (last byte first written to the end[LE])

      Parameters

      • value: Uint8Array

      Returns MaybePromise<void, IsAsync>

    • Write an unsigned integer to the buffer

      Parameters

      • value: number

        The unsigned int to write

      • bytes: number

        How many bytes the unsined int is (If not provided, it will write the minimum length)

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<number> : number

      How many bytes were written (Same as bytes parameter if provided)

    • Write an unsigned integer to the buffer

      Parameters

      • value: bigint

        The unsigned int to write (a bigint)

      • bytes: number

        How many bytes the unsined int is (If not provided, it will write the minimum length)

      Returns MaybePromise<void, IsAsync> extends Promise<unknown> ? Promise<number> : number

      How many bytes were written (Same as bytes parameter)