npm run format:write

This commit is contained in:
2024-12-07 11:19:20 -06:00
parent 03df8fec56
commit 10403a49ca
4 changed files with 44 additions and 34 deletions
+8 -8
View File
@@ -1,6 +1,6 @@
export enum Protocols { export enum Protocols {
SDT = 1 SDT = 1,
}; }
export type UDPPreamble = { export type UDPPreamble = {
preambleSize: number; preambleSize: number;
@@ -114,12 +114,12 @@ export type SDTAckData = {
export type SessionDataTransportPDU = { export type SessionDataTransportPDU = {
vector: SessionDataTransportVectors; vector: SessionDataTransportVectors;
// TODO(jwetzell): cleanup these types // TODO(jwetzell): cleanup these types
data: SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData| Uint8Array; data: SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData | Uint8Array;
}; };
export type SDTClientBlock = { export type SDTClientBlock = {
memberID: number memberID: number;
clientProtocol: number clientProtocol: number;
association: number association: number;
data: SessionDataTransportPDU | Uint8Array data: SessionDataTransportPDU | Uint8Array;
} };
+28 -18
View File
@@ -1,4 +1,15 @@
import { Protocols, SDTAckData, SDTJoinAcceptData, SDTJoinData, SDTJoinRefuseData, SDTLeavingData, SDTWrapperData, SessionDataTransportPDU, SessionDataTransportVectors, TransportLayerAddress } from '../models'; import {
Protocols,
SDTAckData,
SDTJoinAcceptData,
SDTJoinData,
SDTJoinRefuseData,
SDTLeavingData,
SDTWrapperData,
SessionDataTransportPDU,
SessionDataTransportVectors,
TransportLayerAddress,
} from '../models';
import { toHex } from '../utils'; import { toHex } from '../utils';
// TODO(jwetzell): work out flag inheritance, will need previous PDU // TODO(jwetzell): work out flag inheritance, will need previous PDU
@@ -50,8 +61,8 @@ export function decode(bytes: Uint8Array): SessionDataTransportPDU {
} }
function decodeClientBlock(bytes: Uint8Array) { function decodeClientBlock(bytes: Uint8Array) {
if(bytes.byteLength === 0){ if (bytes.byteLength === 0) {
return undefined return undefined;
} }
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -88,34 +99,33 @@ function decodeClientBlock(bytes: Uint8Array) {
const memberID = view.getUint16(vectorOffset); const memberID = view.getUint16(vectorOffset);
const headerOffset = vectorOffset + 2;
const headerOffset = vectorOffset + 2 const clientProtocol = view.getUint32(headerOffset);
const clientProtocol = view.getUint32(headerOffset) const association = view.getUint16(headerOffset + 4);
const association = view.getUint16(headerOffset+4)
const dataOffset = headerOffset + 6; const dataOffset = headerOffset + 6;
// NOTE(jwetzell): flags/lengthH + lengthL + lengthX + vector + header // NOTE(jwetzell): flags/lengthH + lengthL + lengthX + vector + header
const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 2 + 6); const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 2 + 6);
let data: SessionDataTransportPDU | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength) let data: SessionDataTransportPDU | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength);
if (clientProtocol === Protocols.SDT) {
if(clientProtocol === Protocols.SDT){ data = decode(data);
data = decode(data)
} else { } else {
console.error(`SDT client block contains unknown protocol: ${clientProtocol}`) console.error(`SDT client block contains unknown protocol: ${clientProtocol}`);
} }
return { return {
memberID, memberID,
clientProtocol, clientProtocol,
association, association,
data data,
} };
} }
function decodeData(
function decodeData(vector: SessionDataTransportVectors, bytes: Uint8Array): SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData | Uint8Array { vector: SessionDataTransportVectors,
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength) bytes: Uint8Array
): SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData | Uint8Array {
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
switch (vector) { switch (vector) {
case SessionDataTransportVectors.JOIN: { case SessionDataTransportVectors.JOIN: {
const destinationAddress: TransportLayerAddress = { const destinationAddress: TransportLayerAddress = {
+6 -6
View File
@@ -1,7 +1,7 @@
export function toHex(bytes: Uint8Array): string{ export function toHex(bytes: Uint8Array): string {
let hex = ''; let hex = '';
bytes.forEach((byte)=>{ bytes.forEach((byte) => {
hex += byte.toString(16).padStart(2,'0') hex += byte.toString(16).padStart(2, '0');
}) });
return hex; return hex;
} }