-
Notifications
You must be signed in to change notification settings - Fork 0
/
BufferContext.mjs
39 lines (39 loc) · 1.67 KB
/
BufferContext.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { TypedArray } from "./BinaryOperate.mjs";
class BufferContext {
#current;
get current() { return this.#current }
set current(value) {
if (typeof value != "number") throw new TypeError("Value is not a number.");
if (value < 0 || !Number.isInteger(value)) throw new TypeError("Value must be unsign integer.");
if (value > this.#length) throw new Error("Out of range.");
this.#current = value;
}
#data
get data() { return this.#data }
set data(value) { this.#data = value }
#length;
get length() { return this.#length }
#array;
get array() { return this.#array }
get hasNext() { return this.#current < this.#length }
constructor(array, current = 0, data = undefined) {
if (arguments.length < 1) throw new TypeError("Failed to construct 'BufferContext': 1 argument required, but only 0 present.");
if (!(array instanceof TypedArray)) throw new TypeError("Failed to construct 'BufferContext': Argument 'array' is not a TypedArray.");
if (arguments.length > 1) {
if (typeof current != "number") throw new TypeError("Failed to construct 'BufferContext': Argument 'current' is not a number.");
if (current < 0 || !Number.isInteger(current)) throw new TypeError("Failed to construct 'BufferContext': Argument 'current' must be unsign integer.");
if (current > array.length) throw new Error("Failed to construct 'BufferContext': Argument 'current' must not greater than array's length.");
}
this.#current = current;
this.#length = (this.#array = array).length;
this.#data = data;
}
static {
Object.defineProperty(this.prototype, Symbol.toStringTag, {
value: this.name,
configurable: true
});
}
}
export default BufferContext;
export { BufferContext }