cis_interface.serialize package¶
Subpackages¶
Submodules¶
cis_interface.serialize.AsciiTableSerialize module¶
-
class
cis_interface.serialize.AsciiTableSerialize.
AsciiTableSerialize
(*args, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serialize table output into bytes messages comprising a formatted ASCII table.
-
table
¶ AsciiTable – Table object used for formating/parsing table entries.
-
func_deserialize
(msg)[source]¶ Deserialize a message.
Parameters: msg – Message to be deserialized. Returns: Deserialized message. Return type: obj
-
func_serialize
(args)[source]¶ Serialize a message.
Parameters: args – List of arguments to be formatted or numpy array to be serialized. Returns: Serialized message. Return type: bytes, str
-
serializer_type
¶ int – Type of serializer.
-
table_info
¶ dict – Table format information.
-
cis_interface.serialize.DefaultSerialize module¶
-
class
cis_interface.serialize.DefaultSerialize.
DefaultSerialize
(format_str=None, as_array=False, field_names=None, field_units=None, func_serialize=None, func_deserialize=None, **kwargs)[source]¶ Bases:
object
Default class for serializing/deserializing a python object into/from a bytes message.
Parameters: - format_str (str, optional) – If provided, this string will be used to format messages from a list of arguments and parse messages to get a list of arguments in C printf/scanf style. Defaults to None and messages are assumed to already be bytes.
- as_array (bool, optional) – If True, each of the arguments being serialized/deserialized will be arrays that are converted to/from bytes in column major (‘F’) order. Otherwise, each argument should be a scalar. Defaults to False.
- field_names (list, optional) – The names of fields in the format string. If not provided, names are set based on the order of the fields in the format string.
- field_units (list, optional) – The units of fields in the format string. If not provided, all fields are assumed to be dimensionless.
- func_serialize (func, optional) – Callable object that takes python objects as input and returns a bytes string representation. Defaults to None.
- func_deserialize (func, optional) – Callable object that takes a bytes string as input and returns a deserialized python object. Defaults to None.
-
format_str
¶ str – Format string used to format/parse bytes messages from/to a list of arguments in C printf/scanf style.
-
as_array
¶ bool – True or False depending if serialized/deserialized python objects will be arrays or scalars.
-
field_names
¶ list – The names of fields in the format string.
-
field_units
¶ list – The units of fields in the format string.
-
func_serialize
[source]¶ func – Callable object that takes python object as input and returns a bytes string representation.
-
func_deserialize
[source]¶ func – Callable object that takes a bytes string as input and returns a deserialized python object.
-
deserialize
(msg)[source]¶ Deserialize a message.
Parameters: msg (str, bytes) – Message to be deserialized. Returns: Deserialized message and header information. Return type: tuple(obj, dict) Raises: TypeError
– If msg is not bytes type (str on Python 2).
-
empty_msg
¶ obj – Object indicating empty message.
-
field_formats
¶ list – Format codes for each field in the format string.
-
format_header
(header_info)[source]¶ Format header info to form a string that should prepend a message.
Parameters: header_info (dict) – Properties that should be included in the header. Returns: Message with header in front. Return type: str
-
func_deserialize
(msg)[source] Default method for deseserializing a message.
Parameters: msg (str, bytes) – Message to be deserialized. Returns: Deserialized message and header information. Return type: tuple(obj, dict)
-
func_serialize
(args)[source] Default method for serializing object into message.
Parameters: args (obj) – List of arguments to be formatted or a ready made message. Returns: Serialized message. Return type: bytes, str Raises: Exception
– If there is no format string and more than one argument is provided.
-
is_user_defined
¶ bool – True if serialization or deserialization function was user defined.
-
nfields
¶ int – Number of fields in the format string.
-
numpy_dtype
¶ np.dtype – Data type associated with the format string.
-
parse_header
(msg)[source]¶ Extract header info from a message.
Parameters: msg (str) – Message to extract header from. Returns: Message properties. Return type: dict
-
scanf_format_str
¶ str – Simplified format string for scanf.
-
serialize
(args, header_kwargs=None, add_serializer_info=False)[source]¶ Serialize a message.
Parameters: - args (obj) – List of arguments to be formatted or a ready made message.
- header_kwargs (dict, optional) – Keyword arguments that should be added to the header. Defaults to None and no header is added.
- add_serializer_info (bool, optional) – If True, add enough information about this serializer to the header that the message can be recovered.
Returns: Serialized message.
Return type: Raises: TypeError
– If returned msg is not bytes type (str on Python 2).
-
serializer_info
¶ dict – Information about serializer required to reconstruct it.
-
serializer_type
¶ int – Type of serializer.
cis_interface.serialize.MatSerialize module¶
-
class
cis_interface.serialize.MatSerialize.
MatSerialize
(format_str=None, as_array=False, field_names=None, field_units=None, func_serialize=None, func_deserialize=None, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing a python object into a bytes message using the Matlab .mat format.
-
func_deserialize
(msg)[source]¶ Deserialize a message.
Parameters: msg (str, bytes) – Message to be deserialized. Returns: Deserialized Python object. Return type: obj
-
func_serialize
(args)[source]¶ Serialize a message.
Parameters: args (obj) – Python object to be serialized. Returns: Serialized message. Return type: bytes, str Raises: TypeError
– If args is not a dictionary.
-
serializer_type
¶ int – Type of serializer.
-
cis_interface.serialize.PandasSerialize module¶
-
class
cis_interface.serialize.PandasSerialize.
PandasSerialize
(*args, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing/deserializing Pandas data frames.
Parameters: -
empty_msg
¶ obj – Object indicating empty message.
-
func_deserialize
(msg)[source]¶ Deserialize a message.
Parameters: msg (str, bytes) – Message to be deserialized. Returns: Deserialized Python object. Return type: obj
-
func_serialize
(args)[source]¶ Serialize a message.
Parameters: args (obj) – Python object to be serialized. Returns: Serialized message. Return type: bytes, str
-
serializer_type
¶ int – Type of serializer.
-
cis_interface.serialize.PickleSerialize module¶
-
class
cis_interface.serialize.PickleSerialize.
PickleSerialize
(format_str=None, as_array=False, field_names=None, field_units=None, func_serialize=None, func_deserialize=None, **kwargs)[source]¶ Bases:
cis_interface.serialize.DefaultSerialize.DefaultSerialize
Class for serializing a python object into a bytes message by pickling.
-
empty_msg
¶ obj – Object indicating empty message.
-
func_deserialize
(msg)[source]¶ Deserialize a message.
Parameters: msg (str, bytes) – Message to be deserialized. Returns: Deserialized Python object. Return type: obj
-
func_serialize
(args)[source]¶ Serialize a message.
Parameters: args (obj) – Python object to be serialized. Returns: Serialized message. Return type: bytes, str
-
serializer_type
¶ int – Type of serializer.
-