@chickenjdk/byteutils
    Preparing search index...

    Class writableBufferFixedSize

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

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

    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[]]) => void)
        | ((...args: [value: number[]]) => void) = ...

    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>]) => void)
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => void) = ...

    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>]) => void)
        | ((...args: [value: Uint8Array<ArrayBufferLike>]) => void) = ...

    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

    • get length(): number

      The length of the storage

      Returns number

    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.

    • 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 number

      How many bytes were written

    • 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 number

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