@its-c10/dis-codec 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@its-c10/dis-codec",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Spec-accurate Distributed Interactive Simulation (DIS) encode/decode library in TypeScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "build": "tsc",
9
9
  "dev": "tsc -w",
10
10
  "test": "vitest",
11
- "prepublishOnly": "npm run build"
11
+ "prepublishOnly": "npm run build",
12
+ "clean": "rimraf dist"
12
13
  },
13
14
  "keywords": [
14
15
  "dis",
@@ -26,6 +27,7 @@
26
27
  "README.md"
27
28
  ],
28
29
  "devDependencies": {
30
+ "rimraf": "^6.1.3",
29
31
  "typescript": "^5.9.3",
30
32
  "vitest": "^4.1.0"
31
33
  }
package/dist/binary.d.ts DELETED
@@ -1,36 +0,0 @@
1
- /** Big-endian binary I/O (DIS network byte order). */
2
- export declare class BinaryReader {
3
- private readonly view;
4
- private offset;
5
- constructor(buffer: ArrayBuffer);
6
- getOffset(): number;
7
- setOffset(pos: number): void;
8
- skip(bytes: number): void;
9
- private ensureReadable;
10
- readUint8(): number;
11
- readUint16(): number;
12
- readUint32(): number;
13
- readInt8(): number;
14
- readInt16(): number;
15
- readInt32(): number;
16
- readFloat32(): number;
17
- readFloat64(): number;
18
- }
19
- export declare class BinaryWriter {
20
- private buf;
21
- private view;
22
- private offset;
23
- constructor(initialCapacity?: number);
24
- getOffset(): number;
25
- /** Returns a copy of written bytes as ArrayBuffer. */
26
- toArrayBuffer(): ArrayBuffer;
27
- private ensureWritable;
28
- writeUint8(value: number): void;
29
- writeUint16(value: number): void;
30
- writeUint32(value: number): void;
31
- writeInt8(value: number): void;
32
- writeInt16(value: number): void;
33
- writeInt32(value: number): void;
34
- writeFloat32(value: number): void;
35
- writeFloat64(value: number): void;
36
- }
package/dist/binary.js DELETED
@@ -1,144 +0,0 @@
1
- /** Big-endian binary I/O (DIS network byte order). */
2
- export class BinaryReader {
3
- constructor(buffer) {
4
- this.offset = 0;
5
- this.view = new DataView(buffer);
6
- }
7
- getOffset() {
8
- return this.offset;
9
- }
10
- setOffset(pos) {
11
- if (pos < 0 || pos > this.view.byteLength) {
12
- throw new RangeError(`BinaryReader.setOffset: offset ${pos} out of range [0, ${this.view.byteLength}]`);
13
- }
14
- this.offset = pos;
15
- }
16
- skip(bytes) {
17
- if (bytes < 0) {
18
- throw new RangeError(`BinaryReader.skip: negative bytes (${bytes})`);
19
- }
20
- this.ensureReadable(bytes);
21
- this.offset += bytes;
22
- }
23
- ensureReadable(byteCount) {
24
- if (this.offset + byteCount > this.view.byteLength) {
25
- throw new RangeError(`BinaryReader: read past end (need ${byteCount} bytes at offset ${this.offset}, length ${this.view.byteLength})`);
26
- }
27
- }
28
- readUint8() {
29
- this.ensureReadable(1);
30
- const v = this.view.getUint8(this.offset);
31
- this.offset += 1;
32
- return v;
33
- }
34
- readUint16() {
35
- this.ensureReadable(2);
36
- const v = this.view.getUint16(this.offset, false);
37
- this.offset += 2;
38
- return v;
39
- }
40
- readUint32() {
41
- this.ensureReadable(4);
42
- const v = this.view.getUint32(this.offset, false);
43
- this.offset += 4;
44
- return v;
45
- }
46
- readInt8() {
47
- this.ensureReadable(1);
48
- const v = this.view.getInt8(this.offset);
49
- this.offset += 1;
50
- return v;
51
- }
52
- readInt16() {
53
- this.ensureReadable(2);
54
- const v = this.view.getInt16(this.offset, false);
55
- this.offset += 2;
56
- return v;
57
- }
58
- readInt32() {
59
- this.ensureReadable(4);
60
- const v = this.view.getInt32(this.offset, false);
61
- this.offset += 4;
62
- return v;
63
- }
64
- readFloat32() {
65
- this.ensureReadable(4);
66
- const v = this.view.getFloat32(this.offset, false);
67
- this.offset += 4;
68
- return v;
69
- }
70
- readFloat64() {
71
- this.ensureReadable(8);
72
- const v = this.view.getFloat64(this.offset, false);
73
- this.offset += 8;
74
- return v;
75
- }
76
- }
77
- export class BinaryWriter {
78
- constructor(initialCapacity = 64) {
79
- this.offset = 0;
80
- this.buf = new Uint8Array(initialCapacity);
81
- this.view = new DataView(this.buf.buffer, 0, this.buf.byteLength);
82
- }
83
- getOffset() {
84
- return this.offset;
85
- }
86
- /** Returns a copy of written bytes as ArrayBuffer. */
87
- toArrayBuffer() {
88
- const out = new ArrayBuffer(this.offset);
89
- new Uint8Array(out).set(this.buf.subarray(0, this.offset));
90
- return out;
91
- }
92
- ensureWritable(byteCount) {
93
- const need = this.offset + byteCount;
94
- if (need <= this.buf.byteLength)
95
- return;
96
- let cap = this.buf.byteLength;
97
- while (cap < need)
98
- cap = Math.max(cap * 2, need);
99
- const next = new Uint8Array(cap);
100
- next.set(this.buf.subarray(0, this.offset));
101
- this.buf = next;
102
- this.view = new DataView(this.buf.buffer, 0, this.buf.byteLength);
103
- }
104
- writeUint8(value) {
105
- this.ensureWritable(1);
106
- this.view.setUint8(this.offset, value);
107
- this.offset += 1;
108
- }
109
- writeUint16(value) {
110
- this.ensureWritable(2);
111
- this.view.setUint16(this.offset, value, false);
112
- this.offset += 2;
113
- }
114
- writeUint32(value) {
115
- this.ensureWritable(4);
116
- this.view.setUint32(this.offset, value, false);
117
- this.offset += 4;
118
- }
119
- writeInt8(value) {
120
- this.ensureWritable(1);
121
- this.view.setInt8(this.offset, value);
122
- this.offset += 1;
123
- }
124
- writeInt16(value) {
125
- this.ensureWritable(2);
126
- this.view.setInt16(this.offset, value, false);
127
- this.offset += 2;
128
- }
129
- writeInt32(value) {
130
- this.ensureWritable(4);
131
- this.view.setInt32(this.offset, value, false);
132
- this.offset += 4;
133
- }
134
- writeFloat32(value) {
135
- this.ensureWritable(4);
136
- this.view.setFloat32(this.offset, value, false);
137
- this.offset += 4;
138
- }
139
- writeFloat64(value) {
140
- this.ensureWritable(8);
141
- this.view.setFloat64(this.offset, value, false);
142
- this.offset += 8;
143
- }
144
- }
@@ -1,3 +0,0 @@
1
- import type { BinaryReader } from "../../binary/BinaryReader.js";
2
- import type { EntityId } from "../../types/EntityId.js";
3
- export declare function decodeEntityId(reader: BinaryReader): EntityId;
@@ -1,7 +0,0 @@
1
- export function decodeEntityId(reader) {
2
- return {
3
- site: reader.readUint16(),
4
- application: reader.readUint16(),
5
- entity: reader.readUint16(),
6
- };
7
- }
@@ -1,3 +0,0 @@
1
- import type { BinaryWriter } from "../../binary/BinaryWriter.js";
2
- import type { EntityId } from "../../types/EntityId.js";
3
- export declare function encodeEntityId(writer: BinaryWriter, value: EntityId): void;
@@ -1,5 +0,0 @@
1
- export function encodeEntityId(writer, value) {
2
- writer.writeUint16(value.site);
3
- writer.writeUint16(value.application);
4
- writer.writeUint16(value.entity);
5
- }
@@ -1,10 +0,0 @@
1
- import type { BinaryReader } from "../binary.js";
2
- import type { BinaryWriter } from "../binary.js";
3
- /** DIS Entity ID: site, application, entity — each uint16, 6 bytes on wire. */
4
- export interface EntityId {
5
- site: number;
6
- application: number;
7
- entity: number;
8
- }
9
- export declare function decodeEntityId(reader: BinaryReader): EntityId;
10
- export declare function encodeEntityId(writer: BinaryWriter, value: EntityId): void;
@@ -1,12 +0,0 @@
1
- export function decodeEntityId(reader) {
2
- return {
3
- site: reader.readUint16(),
4
- application: reader.readUint16(),
5
- entity: reader.readUint16(),
6
- };
7
- }
8
- export function encodeEntityId(writer, value) {
9
- writer.writeUint16(value.site);
10
- writer.writeUint16(value.application);
11
- writer.writeUint16(value.entity);
12
- }
@@ -1,6 +0,0 @@
1
- /** DIS Entity ID: three unsigned 16-bit fields in order site, application, entity. */
2
- export interface EntityId {
3
- site: number;
4
- application: number;
5
- entity: number;
6
- }
@@ -1 +0,0 @@
1
- export {};