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 {
SDT = 1
};
SDT = 1,
}
export type UDPPreamble = {
preambleSize: number;
@@ -114,12 +114,12 @@ export type SDTAckData = {
export type SessionDataTransportPDU = {
vector: SessionDataTransportVectors;
// TODO(jwetzell): cleanup these types
data: SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData| Uint8Array;
data: SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData | Uint8Array;
};
export type SDTClientBlock = {
memberID: number
clientProtocol: number
association: number
data: SessionDataTransportPDU | Uint8Array
}
memberID: number;
clientProtocol: number;
association: number;
data: SessionDataTransportPDU | Uint8Array;
};
+1 -1
View File
@@ -54,7 +54,7 @@ function decode(bytes: Uint8Array): RootLayerPDU {
if (vector === Protocols.SDT) {
data = pdu.sdt.decode(data);
}
}
return {
vector,
+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';
// TODO(jwetzell): work out flag inheritance, will need previous PDU
@@ -50,8 +61,8 @@ export function decode(bytes: Uint8Array): SessionDataTransportPDU {
}
function decodeClientBlock(bytes: Uint8Array) {
if(bytes.byteLength === 0){
return undefined
if (bytes.byteLength === 0) {
return undefined;
}
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -88,34 +99,33 @@ function decodeClientBlock(bytes: Uint8Array) {
const memberID = view.getUint16(vectorOffset);
const headerOffset = vectorOffset + 2
const clientProtocol = view.getUint32(headerOffset)
const association = view.getUint16(headerOffset+4)
const headerOffset = vectorOffset + 2;
const clientProtocol = view.getUint32(headerOffset);
const association = view.getUint16(headerOffset + 4);
const dataOffset = headerOffset + 6;
// NOTE(jwetzell): flags/lengthH + lengthL + lengthX + vector + header
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){
data = decode(data)
if (clientProtocol === Protocols.SDT) {
data = decode(data);
} else {
console.error(`SDT client block contains unknown protocol: ${clientProtocol}`)
console.error(`SDT client block contains unknown protocol: ${clientProtocol}`);
}
return {
memberID,
clientProtocol,
association,
data
}
data,
};
}
function decodeData(vector: SessionDataTransportVectors, bytes: Uint8Array): SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData | Uint8Array {
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
function decodeData(
vector: SessionDataTransportVectors,
bytes: Uint8Array
): SDTJoinData | SDTJoinAcceptData | SDTJoinRefuseData | SDTWrapperData | SDTAckData | SDTLeavingData | Uint8Array {
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
switch (vector) {
case SessionDataTransportVectors.JOIN: {
const destinationAddress: TransportLayerAddress = {
+7 -7
View File
@@ -1,7 +1,7 @@
export function toHex(bytes: Uint8Array): string{
let hex = '';
bytes.forEach((byte)=>{
hex += byte.toString(16).padStart(2,'0')
})
return hex;
}
export function toHex(bytes: Uint8Array): string {
let hex = '';
bytes.forEach((byte) => {
hex += byte.toString(16).padStart(2, '0');
});
return hex;
}