boing.net.osc
— OSC encoding¶The module boing.net.osc
provides methods and classes for
handling OSC formatted messages.
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.
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).
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.
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.
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.
>>> 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