mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-09-14 18:32:56 +00:00
npm run format:write
This commit is contained in:
@@ -7,10 +7,12 @@ export * from './message';
|
||||
export * from './bundle';
|
||||
|
||||
export function fromBuffer(bytes: Uint8Array): [OSCBundle | OSCMessage | undefined, Uint8Array | undefined] {
|
||||
if (bytes[0] === 47) { // starts with '/'
|
||||
if (bytes[0] === 47) {
|
||||
// starts with '/'
|
||||
return messageFromBuffer(bytes);
|
||||
} else if (bytes[0] === 35) { // starts with '#'
|
||||
return bundleFromBuffer(bytes)
|
||||
} else if (bytes[0] === 35) {
|
||||
// starts with '#'
|
||||
return bundleFromBuffer(bytes);
|
||||
} else {
|
||||
throw new Error('bytes do not look like an OSC message or bundle');
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ const tests = [
|
||||
]),
|
||||
expected: { address: '/oscillator/4/frequency', args: [{ type: 'f', value: 440 }] },
|
||||
},
|
||||
]
|
||||
];
|
||||
|
||||
describe('OSC Bytes Decoding', () => {
|
||||
tests.forEach((bytesTest) => {
|
||||
it(bytesTest.description, () => {
|
||||
const [decoded, remainingBytes] = osc.fromBuffer(bytesTest.bytes);
|
||||
deepEqual(decoded, bytesTest.expected);
|
||||
equal(remainingBytes.length, 0)
|
||||
});
|
||||
equal(remainingBytes.length, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -155,9 +155,7 @@ const badTests = [
|
||||
},
|
||||
{
|
||||
description: 'float64 missing bytes',
|
||||
bytes: new Uint8Array([
|
||||
47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9,
|
||||
]),
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 100, 0, 0, 0x40, 0x29, 0x87, 0xec, 0x82, 0x74, 0xb9]),
|
||||
throwsMessage: { name: /^Error$/, message: /not enough bytes/ },
|
||||
},
|
||||
{
|
||||
@@ -170,7 +168,6 @@ const badTests = [
|
||||
bytes: new Uint8Array([47, 104, 101, 108, 108, 111, 0, 0, 44, 114, 0, 0, 20, 21, 22]),
|
||||
throwsMessage: { name: /^Error$/, message: /must be at least/ },
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
describe('OSC Message Decoding Pass', () => {
|
||||
|
||||
Reference in New Issue
Block a user