run prettier

This commit is contained in:
2024-10-07 12:58:51 -05:00
parent 24e09960d9
commit d295b45228
+31 -32
View File
@@ -18,20 +18,20 @@ const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
let stringEnd = 0; let stringEnd = 0;
let stringPaddingEnd = 0; let stringPaddingEnd = 0;
for (let index = 0; index < bytes.length; index++) { for (let index = 0; index < bytes.length; index++) {
if(bytes[index] === 0){ if (bytes[index] === 0) {
stringEnd = index; stringEnd = index;
stringPaddingEnd = index + 1; stringPaddingEnd = index + 1;
const stringPadding = 4-(stringEnd+1) % 4; const stringPadding = 4 - ((stringEnd + 1) % 4);
if(stringPadding < 4){ if (stringPadding < 4) {
stringPaddingEnd += stringPadding; stringPaddingEnd += stringPadding;
} }
break; break;
} }
} }
return [bytes.toString('ascii', 0, stringEnd), bytes.subarray(stringPaddingEnd)] return [bytes.toString('ascii', 0, stringEnd), bytes.subarray(stringPaddingEnd)];
} },
}, },
f: { f: {
toBuffer: (number) => { toBuffer: (number) => {
@@ -86,22 +86,22 @@ const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
fromString: (string: string) => Buffer.from(string, 'hex'), fromString: (string: string) => Buffer.from(string, 'hex'),
fromBuffer: (buffer) => { fromBuffer: (buffer) => {
const [blobLength, blobBytes] = oscTypeConverterMap.i.fromBuffer(buffer); const [blobLength, blobBytes] = oscTypeConverterMap.i.fromBuffer(buffer);
if (typeof blobLength === 'number'){ if (typeof blobLength === 'number') {
if(blobBytes.length < blobLength){ if (blobBytes.length < blobLength) {
throw new Error('not enough bytes left for blob length specified') throw new Error('not enough bytes left for blob length specified');
} }
const value = blobBytes.subarray(0,blobLength) const value = blobBytes.subarray(0, blobLength);
const blobPadding = 4- (blobLength %4) const blobPadding = 4 - (blobLength % 4);
const blobEnd = blobPadding < 4 ? blobLength + blobPadding : blobLength const blobEnd = blobPadding < 4 ? blobLength + blobPadding : blobLength;
return [value, blobBytes.subarray(blobEnd)] return [value, blobBytes.subarray(blobEnd)];
} else { } else {
throw new Error('unexpected value for blob length') throw new Error('unexpected value for blob length');
} }
}, },
}, },
T: { T: {
toBuffer: () => { toBuffer: () => {
return Buffer.alloc(0) return Buffer.alloc(0);
}, },
fromString: (string: string) => true, fromString: (string: string) => true,
fromBuffer: (buffer) => { fromBuffer: (buffer) => {
@@ -110,13 +110,13 @@ const oscTypeConverterMap: { [key: string]: OSCTypeConverter } = {
}, },
F: { F: {
toBuffer: () => { toBuffer: () => {
return Buffer.alloc(0) return Buffer.alloc(0);
}, },
fromString: (string: string) => false, fromString: (string: string) => false,
fromBuffer: (buffer) => { fromBuffer: (buffer) => {
return [false, buffer]; return [false, buffer];
}, },
} },
}; };
function argsToBuffer(args: OSCArg[]) { function argsToBuffer(args: OSCArg[]) {
@@ -138,7 +138,6 @@ function argsToBuffer(args: OSCArg[]) {
} }
export function messageToBuffer(message: OSCMessage) { export function messageToBuffer(message: OSCMessage) {
const addressBuffer = oscTypeConverterMap.s.toBuffer(message.address); const addressBuffer = oscTypeConverterMap.s.toBuffer(message.address);
if (addressBuffer === undefined) { if (addressBuffer === undefined) {
throw new Error('problem encoding address'); throw new Error('problem encoding address');
@@ -154,42 +153,42 @@ export function messageToBuffer(message: OSCMessage) {
} }
export function messageFromBuffer(bytes: Buffer): OSCMessage | undefined { export function messageFromBuffer(bytes: Buffer): OSCMessage | undefined {
if(bytes[0] !== 47){ if (bytes[0] !== 47) {
throw new Error('osc message must start with a /') throw new Error('osc message must start with a /');
} }
const oscArgs: OSCArg[] = [] const oscArgs: OSCArg[] = [];
const [address, bytesAfterAddress] = oscTypeConverterMap.s.fromBuffer(bytes); const [address, bytesAfterAddress] = oscTypeConverterMap.s.fromBuffer(bytes);
if(typeof address === 'string'){ if (typeof address === 'string') {
let [typeString, bytesAfterType] = oscTypeConverterMap.s.fromBuffer(bytesAfterAddress); let [typeString, bytesAfterType] = oscTypeConverterMap.s.fromBuffer(bytesAfterAddress);
if (typeof typeString === 'string') { if (typeof typeString === 'string') {
if (!typeString.startsWith(',')) { if (!typeString.startsWith(',')) {
throw new Error('osc type string must start with a ,'); throw new Error('osc type string must start with a ,');
} }
let argsBuffer = bytesAfterType let argsBuffer = bytesAfterType;
for (let index = 1; index < typeString.length; index++) { for (let index = 1; index < typeString.length; index++) {
const argType = typeString.charAt(index) as OSCType; const argType = typeString.charAt(index) as OSCType;
const oscTypeConverter = oscTypeConverterMap[argType] const oscTypeConverter = oscTypeConverterMap[argType];
if(oscTypeConverter === undefined){ if (oscTypeConverter === undefined) {
throw new Error('unknown OSC type') throw new Error('unknown OSC type');
} }
const [value, remainingBytes] = oscTypeConverter.fromBuffer(argsBuffer) const [value, remainingBytes] = oscTypeConverter.fromBuffer(argsBuffer);
if(value !== undefined){ if (value !== undefined) {
const arg: OSCArg = { const arg: OSCArg = {
type: argType, type: argType,
value: value value: value,
} };
oscArgs.push(arg) oscArgs.push(arg);
} }
argsBuffer = remainingBytes; argsBuffer = remainingBytes;
} }
return { return {
address, address,
args: oscArgs args: oscArgs,
} };
} }
} }
} }