sc3nb.osc.parsing

Module for parsing OSC packets from sclang.

This implements an extension of the OSC protocol. A bundle is now allowed to consist of other bundles or lists.

This extension is needed as sclang is sending Arrays as this list or when nested as bundles with inner list

Module Contents

Function List

_get_aligned_index

Get next multiple of NUM_SIZE from index

_parse_list

Parse a OSC List

_parse_osc_bundle_element

Parse an element from an OSC bundle.

_parse_bundle

Parsing bundle

parse_sclang_osc_packet

Parses the OSC packet from sclang.

preprocess_return

Preprocessing function for /return values

Content

sc3nb.osc.parsing._LOGGER[source]
sc3nb.osc.parsing.SYNTH_DEF_MARKER = b'SCgf'[source]
sc3nb.osc.parsing.TYPE_TAG_MARKER[source]
sc3nb.osc.parsing.TYPE_TAG_INDEX = 4[source]
sc3nb.osc.parsing.NUM_SIZE = 4[source]
sc3nb.osc.parsing.BYTES_2_TYPE[source]
exception sc3nb.osc.parsing.ParseError[source]

Bases: Exception

Base exception for when a datagram parsing error occurs.

Initialize self. See help(type(self)) for accurate signature.

sc3nb.osc.parsing._get_aligned_index(index: int) int[source]

Get next multiple of NUM_SIZE from index

Parameters:
indexint

starting index

Returns:
int

next multiple of NUM_SIZE from index

sc3nb.osc.parsing._parse_list(dgram: bytes, start_index: int) Tuple[Sequence[Any], int][source]

Parse a OSC List

List consists of the following bytes: 4 bytes (int) : list_size n bytes (string) : OSC type tag n bytes (x) : content as specified by type tag

Parameters:
dgrambytes

datagram with the list

start_indexint

parsing starting index

Returns:
Tuple[Sequence[Any], int]

parsed list contents, starting index + number of consumed bytes

Raises:
ParseError

If datagram is invalid.

sc3nb.osc.parsing._parse_osc_bundle_element(dgram: bytes, start_index: int) Tuple[Union[Sequence[Any], bytes], int][source]

Parse an element from an OSC bundle.

The element needs to be either an OSC bundle or a list

Parameters:
dgrambytes

datagram with the bundle element

start_indexint

parsing starting index

Returns:
Tuple[Union[Sequence[Any], bytes], int]

parsed content of the bundle element, starting index + number of consumed bytes

Raises:
ParseError

If the datagram is invalid.

sc3nb.osc.parsing._parse_bundle(dgram: bytes, start_index: int) Tuple[Sequence[Any], int][source]

Parsing bundle

Parameters:
dgrambytes

datagram with the bundle

start_indexint

parsing starting index

Returns:
tuple[Sequence[Any], int]

parsed content, starting index + number of consumed bytes

Raises:
ParseError

If the datagram is invalid

sc3nb.osc.parsing.parse_sclang_osc_packet(data: bytes) Union[bytes, Sequence[Any]][source]

Parses the OSC packet from sclang.

Parameters:
databytes

bytes sent by sclang

Returns:
bytes or Sequence[Any]

unchanged bytes or content of bundles/messages

sc3nb.osc.parsing.preprocess_return(value: Sequence[Any]) Sequence[Any][source]

Preprocessing function for /return values

Parameters:
valuetuple

return data

Returns:
obj

data