The low-level API provides stateless functions for manual encoding and decoding of OSC data.
Core Functions
| Function | Description | Arguments | Return Value |
| :--- | :--- | :--- | :|
| osc.readPacket() | Decodes binary OSC into JS objects | data (Uint8Array), options (optional), offsetState (optional), length | An osc.js message or bundle object |
| osc.writePacket() | Writes an OSC object to a binary array | packet (message/bundle), options (optional) | A Uint8Array |
Data Structures
Messages:
{
"address": "/an/osc/address",
"args": [ { "type": "f", "value": 440.4 } ]
}
Bundles:
{
"timeTag": { "raw": [123, 456], "native": 167890123 },
"packets": [ { "address": "/msg", "args": [] } ]
}
Argument Objects (with metadata):
When metadata: true is used, arguments include type information:
{
"type": "f",
"value": 444.4
}
Configuration Options
Both the functional API and Port constructors accept an options object:
metadata (boolean, default: false): If true, includes OSC type metadata in arguments.unpackSingleArgs (boolean, default: true): If true, automatically unpacks single-argument messages so args is not wrapped in an extra array.
// Reading a packet
try {
const msg = osc.readPacket(rawUint8Array);
} catch (error) {
console.error(error.message);
}
// Writing a packet
const binaryData = osc.writePacket(myOscObject);