@its-c10/dis-codec 0.1.0 → 0.2.1

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/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # dis-codec
2
2
 
3
- Spec-accurate **Distributed Interactive Simulation (DIS)** encode/decode library in TypeScript. Wire format follows IEEE 1278.1 (DIS application protocols). PDUs are encoded with correct header length for UDP/DIS feeds.
3
+ TypeScript encode/decode library for **Distributed Interactive Simulation (DIS)** with wire format aligned to IEEE 1278.1 (DIS application protocols).
4
+
5
+ This project focuses on a **practical subset of DIS 7 PDUs** (see list below). It is **not** an implementation of the full DIS specification.
4
6
 
5
7
  ## Install
6
8
 
7
9
  ```bash
8
- npm install dis-codec
10
+ npm install @its-c10/dis-codec
9
11
  ```
10
12
 
11
13
  ## Usage
@@ -13,7 +15,7 @@ npm install dis-codec
13
15
  **Encode a PDU and get bytes for UDP:**
14
16
 
15
17
  ```ts
16
- import { BinaryWriter, dis7 } from "dis-codec";
18
+ import { BinaryWriter, dis7 } from "@its-c10/dis-codec";
17
19
 
18
20
  const writer = new BinaryWriter();
19
21
  dis7.encodeCreateEntityPdu(writer, {
@@ -39,7 +41,7 @@ const bytes = new Uint8Array(writer.toArrayBuffer());
39
41
  **Decode a PDU from received bytes:**
40
42
 
41
43
  ```ts
42
- import { BinaryReader, dis7 } from "dis-codec";
44
+ import { BinaryReader, dis7 } from "@its-c10/dis-codec";
43
45
 
44
46
  const reader = new BinaryReader(udpPacketBuffer);
45
47
  const pdu = dis7.decodeEntityStatePdu(reader);
@@ -65,7 +67,7 @@ if (header.pduType === dis7.PDU_TYPE_ENTITY_STATE) {
65
67
  ## DIS 7 PDUs
66
68
 
67
69
  | PDU | Encode / Decode | Notes |
68
- |-----|-----------------|--------|
70
+ |-----|-----------------|-------|
69
71
  | Entity State | `encodeEntityStatePdu` / `decodeEntityStatePdu` | Variable length |
70
72
  | Create Entity | `encodeCreateEntityPdu` / `decodeCreateEntityPdu` | 28 bytes |
71
73
  | Remove Entity | `encodeRemoveEntityPdu` / `decodeRemoveEntityPdu` | 28 bytes |
@@ -74,7 +76,7 @@ if (header.pduType === dis7.PDU_TYPE_ENTITY_STATE) {
74
76
  | Electromagnetic Emission | `encodeElectromagneticEmissionPdu` / `decodeElectromagneticEmissionPdu` | Variable length |
75
77
  | Transmitter | `encodeTransmitterPdu` / `decodeTransmitterPdu` | Variable length |
76
78
 
77
- Constants for PDU types, protocol families, and fixed lengths are on `dis7` (e.g. `dis7.PDU_TYPE_ENTITY_STATE`, `dis7.CREATE_ENTITY_PDU_LENGTH`).
79
+ Constants for PDU types, protocol families, and fixed lengths are available on `dis7` (for example `dis7.PDU_TYPE_ENTITY_STATE` and `dis7.CREATE_ENTITY_PDU_LENGTH`).
78
80
 
79
81
  ## Requirements
80
82
 
@@ -38,6 +38,8 @@ export interface ModulationType {
38
38
  detail: number;
39
39
  radioSystem: number;
40
40
  }
41
+ /** Antenna pattern length in octets for Beam Antenna Pattern. */
42
+ export declare const BEAM_ANTENNA_PATTERN_LENGTH = 40;
41
43
  /**
42
44
  * Beam Antenna Pattern record (320 bits). Table 31.
43
45
  */
@@ -56,8 +58,6 @@ export interface BeamAntennaPattern {
56
58
  eX: number;
57
59
  phase: number;
58
60
  }
59
- /** Antenna pattern length in octets for Beam Antenna Pattern. */
60
- export declare const BEAM_ANTENNA_PATTERN_LENGTH = 40;
61
61
  /** Variable Transmitter Parameters record (variable length). */
62
62
  export interface VariableTransmitterParameter {
63
63
  /** 32-bit enumeration. */
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.1",
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 {};