npm run format:write

This commit is contained in:
2024-10-10 17:10:38 -05:00
parent e831c937c8
commit 304158a97e
3 changed files with 42 additions and 25 deletions
+13 -13
View File
@@ -82,25 +82,25 @@ export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
const contentSizeBuffer = oscTypeConverterMap.i.toBuffer(contentBuffer.length); const contentSizeBuffer = oscTypeConverterMap.i.toBuffer(contentBuffer.length);
if (contentBuffer && contentSizeBuffer) { if (contentBuffer && contentSizeBuffer) {
const buffer = new Uint8Array(contentSizeBuffer.length + contentBuffer.length) const buffer = new Uint8Array(contentSizeBuffer.length + contentBuffer.length);
buffer.set(contentSizeBuffer, 0); buffer.set(contentSizeBuffer, 0);
buffer.set(contentBuffer, contentSizeBuffer.length) buffer.set(contentBuffer, contentSizeBuffer.length);
contentsBuffers.push(buffer); contentsBuffers.push(buffer);
contentsBuffersTotalLength += buffer.length contentsBuffersTotalLength += buffer.length;
} }
} }
}); });
const buffer = new Uint8Array(headerBuffer.length + timeTagBuffer.length + contentsBuffersTotalLength) const buffer = new Uint8Array(headerBuffer.length + timeTagBuffer.length + contentsBuffersTotalLength);
let offset = 0 let offset = 0;
buffer.set(headerBuffer, offset) buffer.set(headerBuffer, offset);
offset += headerBuffer.length offset += headerBuffer.length;
buffer.set(timeTagBuffer, offset) buffer.set(timeTagBuffer, offset);
offset += timeTagBuffer.length offset += timeTagBuffer.length;
contentsBuffers.forEach((contentBuffer)=>{ contentsBuffers.forEach((contentBuffer) => {
buffer.set(contentBuffer, offset) buffer.set(contentBuffer, offset);
offset += contentBuffer.length offset += contentBuffer.length;
}) });
return buffer; return buffer;
} }
+5 -5
View File
@@ -18,12 +18,12 @@ function argsToBuffer(args: OSCArg[]) {
argBuffersTotalLength += buffer.length; argBuffersTotalLength += buffer.length;
} }
} }
const buffer = new Uint8Array(argBuffersTotalLength) const buffer = new Uint8Array(argBuffersTotalLength);
let offset = 0; let offset = 0;
argBuffers.forEach((argBuffer)=>{ argBuffers.forEach((argBuffer) => {
buffer.set(argBuffer,offset) buffer.set(argBuffer, offset);
offset += argBuffer.length offset += argBuffer.length;
}) });
return buffer; return buffer;
} }
+23 -6
View File
@@ -77,7 +77,9 @@ describe('OSC Message Decoding', () => {
it('bad address', () => { it('bad address', () => {
throws( throws(
() => { () => {
osc.messageFromBuffer(new Uint8Array([0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x66,0x00,0x00,0x42,0x0a,0x00,0x00])); osc.messageFromBuffer(
new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x42, 0x0a, 0x00, 0x00])
);
}, },
{ name: /^Error$/, message: /must start with/ } { name: /^Error$/, message: /must start with/ }
); );
@@ -86,7 +88,9 @@ describe('OSC Message Decoding', () => {
it('bad type string', () => { it('bad type string', () => {
throws( throws(
() => { () => {
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x66,0x00,0x00,0x00,0x42,0x0a,0x00])); osc.messageFromBuffer(
new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x42, 0x0a, 0x00])
);
}, },
{ name: /^Error$/, message: /type string must start with/ } { name: /^Error$/, message: /type string must start with/ }
); );
@@ -95,7 +99,11 @@ describe('OSC Message Decoding', () => {
it('unknown type', () => { it('unknown type', () => {
throws( throws(
() => { () => {
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x7a,0x00,0x00,0x42,0x0a,0x00,0x00])); osc.messageFromBuffer(
new Uint8Array([
0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x7a, 0x00, 0x00, 0x42, 0x0a, 0x00, 0x00,
])
);
}, },
{ name: /^Error$/, message: /unknown/ } { name: /^Error$/, message: /unknown/ }
); );
@@ -104,7 +112,9 @@ describe('OSC Message Decoding', () => {
it('float arg missing bytes', () => { it('float arg missing bytes', () => {
throws( throws(
() => { () => {
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x66,0x00,0x00,0x42,0x0a,0x00])); osc.messageFromBuffer(
new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x66, 0x00, 0x00, 0x42, 0x0a, 0x00])
);
}, },
{ name: /^Error$/, message: /not enough bytes/ } { name: /^Error$/, message: /not enough bytes/ }
); );
@@ -113,7 +123,9 @@ describe('OSC Message Decoding', () => {
it('int arg missing bytes', () => { it('int arg missing bytes', () => {
throws( throws(
() => { () => {
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x69,0x00,0x00,0x00,0x00,0x00])); osc.messageFromBuffer(
new Uint8Array([0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00])
);
}, },
{ name: /^Error$/, message: /not enough bytes/ } { name: /^Error$/, message: /not enough bytes/ }
); );
@@ -122,7 +134,12 @@ describe('OSC Message Decoding', () => {
it('blob bytes too small', () => { it('blob bytes too small', () => {
throws( throws(
() => { () => {
osc.messageFromBuffer(new Uint8Array([0x2f,0x68,0x65,0x6c,0x6c,0x6f,0x00,0x00,0x2c,0x62,0x00,0x00,0x00,0x00,0x00,0x04,0x62,0x6c,0x6f])); osc.messageFromBuffer(
new Uint8Array([
0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x2c, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x62, 0x6c,
0x6f,
])
);
}, },
{ name: /^Error$/, message: /not enough bytes/ } { name: /^Error$/, message: /not enough bytes/ }
); );