6.12. boing.net.osc — OSC encoding

The module boing.net.osc provides methods and classes for handling OSC formatted messages.

6.12.1. Container classes

class boing.net.osc.Packet

Abstract base container of OSC data.

encode()
@abc.abstractmethod

Return the encoded representation of this packet.

debug(out, indent="")
@abc.abstractmethod

Write to out a string representation of the OSC packet. The argument indent can be used to format the output.

class boing.net.osc.EncodedPacket(data)

Packet object representing the encoded object data.

decode()

Return the decoded representation of this packet, that is an instance of the class Bundle or Message.

class boing.net.osc.Message(address, typetags="", *arguments)

Packet object representing an OSC Message. The argument address must be a string begginning with the character / (forward slash). The argument typetags must be a string composed by sequence of characters corresponding exactly to the sequence of OSC arguments in the given message. arguments is the list of object contained in the OSC Message.

address

String beginning with the character / (forward slash).

typetags

String composed by a sequence of characters corresponding exactly to the sequence of OSC arguments in the given message.

arguments

List of the arguments of the message.

class boing.net.osc.Bundle(timetag, elements)

Packet object representing an OSC Bundle. The argument timetag must be a datetime.datetime instance or None, while elements should be the list of Packet objects contained in the bundle.

timetag

None or a datetime.datetime instance.

elements

List of Packet objects contained into the bundle.

6.12.2. Encoding and decoding

boing.net.osc.decode(data, source=None)

Return the Packet object decoded from the bytestring data. The argument source can be specified to set the packet source.

The classes Encoder and Decoder provide a standard interface for the OSC encoding.

class boing.net.osc.Encoder

Implements the boing.net.Encoder interface for encoding OSC packet objects into byte strings.

encode(obj)

Return the bytestring obtained from serializing the OSC packet obj.

reset()

NOP method.

class boing.net.osc.Decoder

Implements the boing.net.Decoder interface for converting valid byte string objects into OSC Packet objects.

decode(obj)

Return the list of OSC packets decoded from the bytestring obj.

reset()

NOP method.

6.12.3. Usage example

>>> import sys
>>> import boing.net.osc as osc
>>> source = osc.Message("/tuio/2Dcur", "ss", "source", "test")
>>> alive = osc.Message("/tuio/2Dcur", "ss", "alive", "1")
>>> bundle = osc.Bundle(None,
                        (source, alive,
                         osc.Message("/tuio/2Dcur", "si", "fseq", 1)))
>>> data = bundle.encode()
>>> print(data)
b'#bundle\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00 /tuio/2Dcur\x00,ss\x00source\x00\x00test\x00\x00\x00\x00\x00\x00\x00\x1c/tuio/2Dcur\x00,ss\x00alive\x00\x00\x001\x00\x00\x00\x00\x00\x00\x1c/tuio/2Dcur\x00,si\x00fseq\x00\x00\x00\x00\x00\x00\x00\x01'
>>> packet = osc.decode(data)
>>> print(packet)
<Bundle instance at 0x1b756d0 [@None, 3 element(s)]>
>>> packet.debug(sys.stdout)
Bundle IMMEDIATELY
 | /tuio/2Dcur ss 'source' 'test'
 | /tuio/2Dcur ss 'alive' '1'
 | /tuio/2Dcur si 'fseq' 1