arrayBuffer 에 저장된 byte 들을 특정 타입으로 해석하여 돌려줍니다. FileStream.read() 의 구현을 위해 사용되는 함수들입니다. 직접 사용하기보다는 FileStream 을 생성하여 사용할 것을 권장합니다.

Syntax

toFloat(arrayBuffer, byteOffset, littleEndian)
toDouble(arrayBuffer, byteOffset, littleEndian)
toInt8(arrayBuffer, byteOffset, littleEndian)
toInt16(arrayBuffer, byteOffset, littleEndian)
toInt32(arrayBuffer, byteOffset, littleEndian)
toInt64(arrayBuffer, byteOffset)
toUint8(arrayBuffer, byteOffset)
toUint16(arrayBuffer, byteOffset, littleEndian)
toUint32(arrayBuffer, byteOffset, littleEndian)
toUint64(arrayBuffer, byteOffset, littleEndian)
toVector2f(arrayBuffer, byteOffset, littleEndian)
toVector3f(arrayBuffer, byteOffset, littleEndian)
toVector4f(arrayBuffer, byteOffset, littleEndian)
toVector2(arrayBuffer, byteOffset, littleEndian)
toVector3(arrayBuffer, byteOffset, littleEndian)
toVector4(arrayBuffer, byteOffset, littleEndian)

Parameters

arrayBuffer

byte 를 읽을 ArrayBuffer .

byteOffset

ArrayBuffer 에서 읽을 첫번째 byte 의 인덱스(index).

littleEndian

byte 들이 little endian 순서로 저장되어있는지 여부. 인자를 주지 않으면 littleEndian = true 라고 생각합니다.

Return value

number | bigint | Vector2 | Vector3 | Vector4

Example

function example() {
    const float    = new Uint8Array([0xd8, 0xf, 0x49, 0x40]).buffer;
    const double   = new Uint8Array([0, 0, 0, 0, 0xfb, 0x21, 0x9, 0x40]).buffer;
    const utf8str  = new Uint8Array([0xec, 0x95, 0x88, 0xeb, 0x87, 0xbd, 0]).buffer;
    const utf16str = new Uint8Array([0x52, 0xD8, 0x62, 0xDF]).buffer;
    
    const int8  = new Uint8Array([0xfe]).buffer;
    const uint8 = new Uint8Array([0xfe]).buffer;

    const int16  = new Uint8Array([0xf0, 0xff]).buffer;
    const uint16 = new Uint8Array([0xf0, 0xff]).buffer;

    const int32  = new Uint8Array([0xf0, 0xff, 0xff, 0xff]).buffer;
    const uint32 = new Uint8Array([0xf0, 0xff, 0xff, 0xff]).buffer;

    const int64  = new Uint8Array([0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]).buffer;
    const uint64 = new Uint8Array([0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]).buffer;

    console.log(toFloat(float));                                  // 3.141592025756836
    console.log(toDouble(double));                                // 3.141592025756836
    console.log(toUtf8String(utf8str, 0, utf8str.byteLength));    // 안뇽
    console.log(toUtf16String(utf16str, 0, utf16str.byteLength)); // 𤭢

    console.log(toInt8(int8));   // -2
    console.log(toUint8(uint8)); // 254

    console.log(toInt16(int16));   // -16
    console.log(toUint16(uint16)); // 65520

    console.log(toInt32(int32));   // -16
    console.log(toUint32(uint32)); // 4294967280

    console.log(toInt64(int64));   // -16n
    console.log(toUint64(uint64)); // 18446744073709551600n
}