natnet.protocol.common¶
Utilities for protocol package.
Copyright (c) 2017, Matthew Edwards. This file is subject to the 3-clause BSD license, as found in the LICENSE file in the top-level directory of this distribution and at https://github.com/mje-nz/python_natnet/blob/master/LICENSE. No part of python_natnet, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file.
-
class
natnet.protocol.common.MessageId[source]¶ Message IDs for each NatNet message (as in NatNetTypes.h).
Variables: - Connect – Request for server info
- ServerInfo – Motive version, NatNet version, clock frequency, data port, and multicast address
- RequestModelDef – Request for model definitions
- ModelDef – List of definitions of rigid bodies, markersets, skeletons etc
- FrameOfData – Frame of motion capture data
- EchoRequest – Request server to immediately respond with its current time (used for clock sync)
- EchoResponse – Current server time (and time contained in EchoRequest message)
-
class
natnet.protocol.common.ParseBuffer(data)[source]¶ Buffer handling logic.
Contains a buffer and an offset, and provides methods for unpacking data types (as struct.Struct instances) from the buffer.
-
class
natnet.protocol.common.SerDesRegistry(implementation_types=NOTHING, version=Version(major=3, minor=0, build=0, revision=0))[source]¶ Registry of message implementations, which can serialize messages and deserialize packets.
An instance of this is used to provide the module-level function.
-
deserialize(data, version=None, strict=False)[source]¶ Deserialize a packet into a message instance.
Parameters: - data (bytes) – A NatNet packet
- version (Version) – Protocol version to use when deserializing
- strict (bool) – Raise an exception if there is data left in the buffer after parsing.
Returns: Message instance
-
static
deserialize_header(data)[source]¶ Deserialize a packet into message ID and payload.
Parameters: data (bytes) – A NatNet packet Returns: tuple[MessageId, ParseBuffer] – Message ID and raw payload
-
deserialize_payload(message_id, payload_data, version=None, strict=False)[source]¶ Deserialize the payload of a packet into a message instance.
Parameters: - message_id (MessageId)
- payload_data (ParseBuffer) – raw payload
- version (Version) – Protocol version to use when deserializing
- strict (bool) – Raise an exception if there is data left in the buffer after parsing
Returns: Message instance
-
-
class
natnet.protocol.common.Version[source]¶ NatNet version, with correct comparison operator.
Believe it or not, this is performance-critical.
Variables: - major (int) –
- minor (int) –
- build (int) –
- revision (int) –
-
natnet.protocol.common.deserialize(*args, **kwargs)[source]¶ Deserialize a packet into a message instance.
Parameters: - data (bytes) – A NatNet packet
- version (Version) – Protocol version to use when deserializing
- strict (bool) – Raise an exception if there is data left in the buffer after parsing.
Returns: Message instance
-
natnet.protocol.common.deserialize_header(*args, **kwargs)[source]¶ Deserialize a packet into message ID and payload.
Parameters: data (bytes) – A NatNet packet Returns: tuple[MessageId, ParseBuffer] – Message ID and raw payload
-
natnet.protocol.common.deserialize_payload(*args, **kwargs)[source]¶ Deserialize the payload of a packet into a message instance.
Parameters: - message_id (MessageId)
- payload_data (ParseBuffer) – raw payload
- version (Version) – Protocol version to use when deserializing
- strict (bool) – Raise an exception if there is data left in the buffer after parsing
Returns: Message instance