UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

25 lines 1.19 kB
import { isLittleEndian } from "../../web-assembly/util/is-little-endian.js"; export class ATypedTupleFactory { constructor(elementCount, bytesPerElement, dataView) { this.elementCount = elementCount; this.bytesPerElement = bytesPerElement; this.dataView = dataView; } copyFromBuffer(memoryDataView, pointer, writeTo = this.createOneEmpty(), littleEndian = ATypedTupleFactory.littleEndian) { const bytesPerElement = this.bytesPerElement; for (let i = 0, iEnd = this.elementCount; i < iEnd; ++i) { writeTo[i] = this.dataView.getValue(memoryDataView, pointer, littleEndian); pointer += bytesPerElement; } return writeTo; } copyToBuffer(memoryDataView, writeFrom, pointer, littleEndian = ATypedTupleFactory.littleEndian) { const bytesPerElement = this.bytesPerElement; for (let i = 0, iEnd = this.elementCount; i < iEnd; ++i) { this.dataView.setValue(memoryDataView, pointer, writeFrom[i], littleEndian); pointer += bytesPerElement; } } } ATypedTupleFactory.littleEndian = isLittleEndian; //# sourceMappingURL=a-typed-tuple-factory.js.map