-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Summary
Create protocol-specific base classes that enforce byte order at the type level to prevent mixing Big Endian (NPS) and Little Endian (MCOTS) protocols.
Background
From the packet architecture analysis:
- NPS Protocol (ports 7003, 8226, 8228): Uses Big Endian
- MCOTS Protocol (port 43300): Uses Little Endian
- Current issue:
BytableBase.coerceValueToBufferuses LE, butBytableMessage.htonluses BE - this inconsistency can cause bugs
Proposed Solution
Create new base classes:
// libs/@rustymotors/binary/src/lib/NPSPacketBase.ts
export abstract class NPSPacketBase extends BytableMessage {
protected static readonly ENDIANNESS = 'BE' as const;
protected writeUInt16(buffer: Buffer, value: number, offset: number): void {
buffer.writeUInt16BE(value, offset);
}
protected writeUInt32(buffer: Buffer, value: number, offset: number): void {
buffer.writeUInt32BE(value, offset);
}
}
// libs/@rustymotors/binary/src/lib/MCOTSPacketBase.ts
export abstract class MCOTSPacketBase extends BytableServerMessage {
protected static readonly ENDIANNESS = 'LE' as const;
protected writeUInt16(buffer: Buffer, value: number, offset: number): void {
buffer.writeUInt16LE(value, offset);
}
protected writeUInt32(buffer: Buffer, value: number, offset: number): void {
buffer.writeUInt32LE(value, offset);
}
}Tasks
- Create
NPSPacketBaseclass inlibs/@rustymotors/binary/ - Create
MCOTSPacketBaseclass inlibs/@rustymotors/binary/ - Fix
BytableBase.coerceValueToBufferto be protocol-aware or deprecate it - Add tests for byte order enforcement
- Update documentation
Dependencies
- Depends on: Centralize message ID constants for protocol discoverability #2801 (Phase 1: Message ID constants)
Related
Part of the packet architecture improvement initiative. See PR #2801 for context.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
No status