mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-09-01 04:09:00 +00:00
fromBuffer methods should return any unprocessed results
This commit is contained in:
@@ -2,7 +2,7 @@ import { messageFromBuffer, messageToBuffer } from './message';
|
|||||||
import { OSCBundle } from './models';
|
import { OSCBundle } from './models';
|
||||||
import { oscTypeConverterMap } from './osc-types';
|
import { oscTypeConverterMap } from './osc-types';
|
||||||
|
|
||||||
export function bundleFromBuffer(bytes: Uint8Array): OSCBundle | undefined {
|
export function bundleFromBuffer(bytes: Uint8Array): [OSCBundle | undefined, Uint8Array | undefined] {
|
||||||
if (bytes.length < 8) {
|
if (bytes.length < 8) {
|
||||||
throw new Error('bundle has to be at least 20 bytes');
|
throw new Error('bundle has to be at least 20 bytes');
|
||||||
}
|
}
|
||||||
@@ -33,13 +33,13 @@ export function bundleFromBuffer(bytes: Uint8Array): OSCBundle | undefined {
|
|||||||
|
|
||||||
if (bundleContentBytes[0] === 35) {
|
if (bundleContentBytes[0] === 35) {
|
||||||
// # character indicating contents is a bundle
|
// # character indicating contents is a bundle
|
||||||
const content = bundleFromBuffer(bundleContentBytes);
|
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
|
||||||
if (content) {
|
if (content) {
|
||||||
bundleContents.push(content);
|
bundleContents.push(content);
|
||||||
}
|
}
|
||||||
} else if (bundleContentBytes[0] === 47) {
|
} else if (bundleContentBytes[0] === 47) {
|
||||||
const content = messageFromBuffer(bundleContentBytes);
|
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
|
||||||
if (content) {
|
if (content && content !== undefined) {
|
||||||
bundleContents.push(content);
|
bundleContents.push(content);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -51,12 +51,13 @@ export function bundleFromBuffer(bytes: Uint8Array): OSCBundle | undefined {
|
|||||||
endOfBundle = true;
|
endOfBundle = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return [{
|
||||||
|
timeTag,
|
||||||
|
contents: bundleContents,
|
||||||
|
},remainingBytes];
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return [undefined, undefined]
|
||||||
timeTag,
|
|
||||||
contents: bundleContents,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
|
export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export function messageToBuffer(message: OSCMessage): Uint8Array {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function messageFromBuffer(bytes: Uint8Array): OSCMessage | undefined {
|
export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, Uint8Array | 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 /');
|
||||||
}
|
}
|
||||||
@@ -78,11 +78,11 @@ export function messageFromBuffer(bytes: Uint8Array): OSCMessage | undefined {
|
|||||||
}
|
}
|
||||||
argsBuffer = remainingBytes;
|
argsBuffer = remainingBytes;
|
||||||
}
|
}
|
||||||
|
return [{
|
||||||
return {
|
|
||||||
address,
|
address,
|
||||||
args: oscArgs,
|
args: oscArgs,
|
||||||
};
|
}, argsBuffer];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return [undefined, undefined]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user