cis_interface.serialize package

Submodules

cis_interface.serialize.AsciiMapSerialize module

class cis_interface.serialize.AsciiMapSerialize.AsciiMapSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.serialize.DefaultSerialize.DefaultSerialize

Class for serializing/deserializing name/value mapping.

Parameters:
  • delimiter (str, optional) – Delimiter that should be used to separate name/value pairs in the map. Defaults to t.
  • newline (str, optional) – Delimiter that should be used to separate lines. Defaults to n.
func_deserialize(msg)[source]

Deserialize a message.

Parameters:msg (str, bytes) – Message to be deserialized.
Returns:Deserialized Python dictionary.
Return type:dict
func_serialize(args)[source]

Serialize a message.

Parameters:args (dict) – Python dictionary to be serialized.
Returns:Serialized message.
Return type:bytes, str
classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict

cis_interface.serialize.AsciiTableSerialize module

class cis_interface.serialize.AsciiTableSerialize.AsciiTableSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.serialize.DefaultSerialize.DefaultSerialize

Class for serialize table output into bytes messages comprising a formatted ASCII table.

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.
  • 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.
  • 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.
  • delimiter (str, optional) – Character(s) that should be used to separate columns. Defaults to ‘t’.
  • use_astropy (bool, optional) – If True, the astropy package will be used to serialize/deserialize table. Defaults to False.
  • **kwargs – Additional keyword args are processed as part of the type definition.
format_str

Format string used to format/parse bytes messages from/to a list of arguments in C printf/scanf style.

Type:str
field_names

The names of fields in the format string.

Type:list
field_units

The units of fields in the format string.

Type:list
as_array

True or False depending if serialized/deserialized python objects will be arrays or scalars.

Type:bool
delimiter

Character(s) that should be used to separate columns.

Type:str
use_astropy

If True, the astropy package will be used to serialize/deserialize table.

Type:bool
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
classmethod get_testing_options(as_array=False)[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict
update_field_names()[source]

list: Names for each field in the data type.

update_field_units()[source]

list: Units for each field in the data type.

update_format_str()[source]

Update the format string based on the type definition.

update_serializer(*args, **kwargs)[source]

Update serializer with provided information.

Parameters:
  • extract (bool, optional) – If True, the updated typedef will be the bare minimum as extracted from total set of provided keywords, otherwise the entire set will be sued. Defaults to False.
  • skip_type (bool, optional) – If True, everything is updated except the data type. Defaults to False.
  • **kwargs – Additional keyword arguments are processed as part of they type definition and are parsed for old-style keywords.
Raises:

RuntimeError – If there are keywords that are not valid typedef keywords (currect or old-style).

cis_interface.serialize.DefaultSerialize module

class cis_interface.serialize.DefaultSerialize.DefaultSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.tools.CisClass

Default class for serializing/deserializing a python object into/from a bytes message.

Parameters:
  • 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.
  • encode_func_serialize (bool, optional) – If True, the data returned by func_serialize (if provided) will be encoded. If False, the data returned by func_serialize will not be encoded. Defaults to None and is not used.
  • decode_func_deserialize (bool, optional) – If True, the data passed to func_deserialize (if provided) will be decoded first. If False, the data passed to func_deserialize will not be decoded. Defaults to None and is not used.
  • func_typedef (dict, optional) – Type definition for encoding/decoding messages returned/passed by/to func_serialize/func_deserialize. Defaults to None and is not used.
  • **kwargs – Additional keyword args are processed as part of the type definition.
func_serialize

Callable object that takes python object as input and returns a bytes string representation.

Type:func
func_deserialize

Callable object that takes a bytes string as input and returns a deserialized python object.

Type:func
encode_func_serialize

If True, the data returned by func_serialize (if provided) will be encoded. If False, the data returned by func_serialize will not be encoded.

Type:bool
decode_func_deserialize

If True, the data passed to func_deserialize (if provided) will be decoded first. If False, the data passed to func_deserialize will not be decoded.

Type:bool
func_typedef

Type definition for encoding/decoding messages returned/passed by/to func_serialize/func_deserialize.

Type:dict
__getattribute__(name)[source]

Return alias result if there is one.

consolidate_array(out)[source]

Consolidate message into a structure numpy array if possible.

Parameters:out (list, tuple, np.ndarray) – Object to consolidate into a structured numpy array.
Returns:Structured numpy array containing consolidated message.
Return type:np.ndarray
Raises:ValueError – If the array cannot be consolidated.
decode_func_deserialize = False
deserialize(msg, **kwargs)[source]

Deserialize a message.

Parameters:
  • msg (str, bytes) – Message to be deserialized.
  • **kwargs – Additional keyword arguments are passed to the deserialize method of the datatype class.
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

Object indicating empty message.

Type:obj
encode_func_serialize = False
func_typedef = {'type': 'bytes'}
get_field_names(as_bytes=False)[source]

Get the field names for an array of fields.

Parameters:as_bytes (bool, optional) – If True, the field names will be returned as bytes. If False the field names will be returned as unicode. Defaults to False.
Returns:Names for each field in the data type.
Return type:list
get_field_units(as_bytes=False)[source]

Get the field units for an array of fields.

Parameters:as_bytes (bool, optional) – If True, the field units will be returned as bytes. If False the field units will be returned as unicode. Defaults to False.
Returns:Units for each field in the data type.
Return type:list
classmethod get_testing_options(as_format=False, as_array=False)[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing. Key/value pairs:
  • kwargs (dict): Keyword arguments for comms tested with the provided content.
  • empty (object): Object produced from deserializing an empty message.
  • objects (list): List of objects to be serialized/deserialized. extra_kwargs (dict): Extra keyword arguments not used to construct type definition.
  • typedef (dict): Type definition resulting from the supplied kwargs.
  • dtype (np.dtype): Numpy data types that is consistent with the determined type definition.
Return type:dict
initialize_from_message(msg, **metadata)[source]

Initialize the serializer based on recieved message.

Parameters:
  • msg (object) – Message that serializer should be initialized from.
  • **kwargs – Additional keyword arguments are treated as metadata that may contain additional information for initializing the serializer.
initialize_serializer(metadata, extract=False)[source]

Initialize a serializer based on received metadata. This method will exit early if the serializer has already been intialized.

Parameters:
  • metadata (dict) – Header information including type info that should be used to initialize the serializer class.
  • extract (bool, optional) – If True, the type will be defined using a subset of the type information in metadata. If False, all of the type information will be used. Defaults to False.
numpy_dtype

Corresponding structured data type. Will be None unless the type is an array of 1darrays.

Type:np.dtype
parse_header(msg)[source]

Extract header info from a message.

Parameters:msg (str) – Message to extract header from.
Returns:Message properties.
Return type:dict
classmethod seri_kws()[source]

Get a list of valid keyword arguments.

serialize(args, header_kwargs=None, add_serializer_info=False, no_metadata=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, serializer information will be added to the metadata. Defaults to False.
  • no_metadata (bool, optional) – If True, no metadata will be added to the serialized message. Defaults to False.
Returns:

Serialized message.

Return type:

bytes, str

Raises:

TypeError – If returned msg is not bytes type (str on Python 2).

serializer_info

Serializer info.

Type:dict
typedef

Type definition.

Type:dict
update_serializer(extract=False, skip_type=False, **kwargs)[source]

Update serializer with provided information.

Parameters:
  • extract (bool, optional) – If True, the updated typedef will be the bare minimum as extracted from total set of provided keywords, otherwise the entire set will be sued. Defaults to False.
  • skip_type (bool, optional) – If True, everything is updated except the data type. Defaults to False.
  • **kwargs – Additional keyword arguments are processed as part of they type definition and are parsed for old-style keywords.
Raises:

RuntimeError – If there are keywords that are not valid typedef keywords (currect or old-style).

update_typedef_from_oldstyle(typedef)[source]

Update a given typedef using an old, table-style serialization spec. Existing typedef values are not overwritten and warnings are raised if the provided serialization spec is not compatible with the type definition.

Parameters:typedef (dict) – Type definition to update.
Returns:Updated typedef.
Return type:dict

cis_interface.serialize.DirectSerialize module

class cis_interface.serialize.DirectSerialize.DirectSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.serialize.DefaultSerialize.DefaultSerialize

Class for directly serializing bytes.

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
classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns:
Dictionary of variables to use for testing. Key/value pairs:
kwargs (dict): Keyword arguments for comms tested with the
provided content.
empty (object): Object produced from deserializing an empty
message.

objects (list): List of objects to be serialized/deserialized. extra_kwargs (dict): Extra keyword arguments not used to

construct type definition.
typedef (dict): Type definition resulting from the supplied
kwargs.
dtype (np.dtype): Numpy data types that is consistent with the
determined type definition.
Return type:dict

cis_interface.serialize.JSONSerialize module

class cis_interface.serialize.JSONSerialize.JSONSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.serialize.DefaultSerialize.DefaultSerialize

Class for serializing a python object into a bytes message using JSON.

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
classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict

cis_interface.serialize.MatSerialize module

class cis_interface.serialize.MatSerialize.MatSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=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.
classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict

cis_interface.serialize.ObjSerialize module

class cis_interface.serialize.ObjSerialize.ObjSerialize(*args, **kwargs)[source]

Bases: cis_interface.serialize.PlySerialize.PlySerialize

Class for serializing/deserializing .obj file formats. Reader adapted from https://www.pygame.org/wiki/OBJFileLoader.

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
classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict

cis_interface.serialize.PandasSerialize module

class cis_interface.serialize.PandasSerialize.PandasSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.serialize.AsciiTableSerialize.AsciiTableSerialize

Class for serializing/deserializing Pandas data frames.

Parameters:
  • delimiter (str, optional) – Delimiter that should be used to serialize pandas data frames to/from csv style files. Defaults to t.
  • write_header (bool, optional) – If True, headers will be added to serialized tables. Defaults to True.
apply_field_names(frame)[source]

Apply field names as columns to a frame, first checking for a mapping. If there is a direct mapping, the columns are reordered to match the order of the field names. If there is not an overlap in the field names and columns, a one-to-one mapping is assumed, but a warning is issued. If there is a partial overlap, an error is raised.

Parameters:frame (pandas.DataFrame) – Frame to apply field names to as columns.
Returns:Frame with updated field names.
Return type:pandas.DataFrame
Raises:RuntimeError – If there is a partial overlap between the field names and columns.
empty_msg

Object indicating empty message.

Type:obj
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
classmethod get_testing_options(no_names=False, **kwargs)[source]

Method to return a dictionary of testing options for this class.

Parameters:no_names (bool, optional) – If True, an example is returned where the names are not provided to the deserializer. Defaults to False.
Returns:Dictionary of variables to use for testing.
Return type:dict

cis_interface.serialize.PickleSerialize module

class cis_interface.serialize.PickleSerialize.PickleSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.serialize.DefaultSerialize.DefaultSerialize

Class for serializing a python object into a bytes message by pickling.

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
classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict

cis_interface.serialize.PlySerialize module

class cis_interface.serialize.PlySerialize.PlySerialize(*args, **kwargs)[source]

Bases: cis_interface.serialize.DefaultSerialize.DefaultSerialize

Class for serializing/deserializing .ply file formats.

Parameters:
  • write_header (bool, optional) – If True, headers will be added to serialized output. Defaults to True.
  • newline (str, optional) – String that should be used for new lines. Defaults to ‘n’.
write_header

If True, headers will be added to serialized output.

Type:bool
newline

String that should be used for new lines.

Type:str
default_rgb

Default color in RGB that should be used for missing colors.

Type:list
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
classmethod get_testing_options()[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict

cis_interface.serialize.YAMLSerialize module

class cis_interface.serialize.YAMLSerialize.YAMLSerialize(func_serialize=None, func_deserialize=None, encode_func_serialize=None, decode_func_deserialize=None, func_typedef=None, **kwargs)[source]

Bases: cis_interface.serialize.DefaultSerialize.DefaultSerialize

Class for serializing a python object into a bytes message using YAML.

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
classmethod get_testing_options(**kwargs)[source]

Method to return a dictionary of testing options for this class.

Returns:Dictionary of variables to use for testing.
Return type:dict

Module contents