-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstruct.ts
58 lines (50 loc) · 1.12 KB
/
struct.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @module
*
* Struct type.
*/
import { Endian } from './endian.ts';
import type { MemberInfos, Members } from './members.ts';
import type { Type } from './type.ts';
import { constant } from './util.ts';
let members: WeakMap<typeof Struct, MemberInfos>;
/**
* Binary structure buffer view.
*/
export class Struct extends Endian implements Type, Members {
/**
* Struct class.
*/
declare public readonly ['constructor']: Omit<typeof Struct, 'new'>;
public get byteLength(): number {
return this.constructor.BYTE_LENGTH;
}
/**
* Byte length of struct.
*/
public static readonly BYTE_LENGTH: number = 0;
/**
* Non-overlapping members.
*/
public static readonly OVERLAPPING: boolean = false;
/**
* Members infos.
*/
public static get MEMBERS(): MemberInfos {
let r = (members ??= new WeakMap()).get(this);
if (!r) {
members.set(
this,
r = Object.create(
Object.getPrototypeOf(this).MEMBERS ?? null,
) as MemberInfos,
);
}
return r;
}
static {
constant(this.prototype, Symbol.toStringTag, 'Struct');
constant(this, 'BYTE_LENGTH');
constant(this, 'OVERLAPPING');
}
}