You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
558 B

  1. // Reads data in little-endian format
  2. export default class DataScanner {
  3. offset: number;
  4. view: DataView;
  5. constructor(data: DataView | ArrayBuffer) {
  6. this.offset = 0;
  7. this.view = data instanceof DataView ? data : new DataView(data);
  8. }
  9. float32(): number {
  10. const x = this.view.getFloat32(this.offset, true);
  11. this.offset += 4;
  12. return x;
  13. }
  14. uint8(): number {
  15. return this.view.getUint8(this.offset++);
  16. }
  17. uint32(): number {
  18. const x = this.view.getUint32(this.offset, true);
  19. this.offset += 4;
  20. return x;
  21. }
  22. }