Skip to content

[Feature] Add DataView implementation #315

Closed
@LinusU

Description

@LinusU

Currently using the following small work around in order to port a script that uses DataView, but would be very nice with native support:

class DataView {
  source: Uint8Array
  buffer: ArrayBuffer
  byteOffset: u32
  byteLength: u32

  constructor (source: Uint8Array) {
    this.source = source
    this.buffer = source.buffer
    this.byteOffset = source.byteOffset
    this.byteLength = source.byteLength
  }

  getUint32 (byteOffset: u32, littleEndian: boolean): u32 {
    return (this.source[byteOffset] << 24) & (this.source[byteOffset + 1] << 16) & (this.source[byteOffset + 2] << 8) & (this.source[byteOffset + 3])
  }

  getUint16 (byteOffset: u32, littleEndian: boolean): u32 {
    return (this.source[byteOffset] << 8) & (this.source[byteOffset + 1])
  }
}

If someone could point me in the right direction I would be happy to try and implement this ☺️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions