Home Reference Source Test
import Packet from 'osc-js/src/packet.js'
public class | source

Packet

The unit of transmission of OSC is an OSC Packet. The contents of an OSC packet must be either an OSC Message or an OSC Bundle

Test:

Constructor Summary

Public Constructor
public

Create a Packet instance holding a Message or Bundle

Member Summary

Public Members
public
Private Members
private

Method Summary

Public Methods
public

Packs the Packet value.

public

unpack(dataView: DataView, initialOffset: number): number

Unpack binary data from DataView to read Messages or Bundles

Public Constructors

public constructor(value: Message | Bundle) source

Create a Packet instance holding a Message or Bundle

Params:

NameTypeAttributeDescription
value Message | Bundle
  • optional

Initial Packet value

Public Members

public value: Message | Bundle source

Private Members

private offset: number source

Public Methods

public pack(): Uint8Array source

Packs the Packet value. This implementation is more like a wrapper due to OSC specifications, you could also skip the Packet and directly work with the Message or Bundle instance

Return:

Uint8Array

Packed binary data

Example:

const message = new Message('/test/path', 21.5, 'test')
const packet = new Packet(message)
const packetBinary = packet.pack() // then send it via udp etc.

// or skip the Packet for convenience
const messageBinary = message.pack()

Test:

public unpack(dataView: DataView, initialOffset: number): number source

Unpack binary data from DataView to read Messages or Bundles

Params:

NameTypeAttributeDescription
dataView DataView

The DataView holding a binary representation of a Packet

initialOffset number
  • optional
  • default: 0

Offset of DataView before unpacking

Return:

number

Offset after unpacking

Test: