module documentation

Library for Python message generation.

The structure of the serialization descends several levels of serializers:
  • msg_generator: generator for an individual msg file
  • serialize_fn_generator: generator for msg.serialize() - serializer_generator

    • field-type-specific serializers
      raise MsgGenerationException("unknown file extension: %s"%f)
  • deserialize_fn_generator: generator for msg.deserialize() - serializer_generator

    • field-type-specific serializers
Class Generator No class docstring; 0/4 instance variable, 1/3 method documented
Class MsgGenerator Generate Python message code for all messages in a package.
Class Special No class docstring; 0/3 instance variable, 2/2 methods documented
Class SrvGenerator Undocumented
Function array_serializer_generator Generator for array types.
Function complex_serializer_generator Generator for serializing complex type.
Function compute_constructor Compute python constructor expression for specified message type implementation.
Function compute_full_text_escaped Escape the result of genmsg.compute_full_text.
Function compute_import Compute python import statement for specified message type implementation.
Function compute_outfile_name No summary
Function compute_pkg_type No summary
Function compute_post_deserialize Compute post-deserialization code for type_, if necessary.
Function compute_resource_name Convert resource filename to ROS resource name.
Function default_value Compute default value for field_type.
Function deserialize_fn_generator Generator for body of deserialize() function.
Function flatten Flatten the msg spec so that embedded message fields become direct references.
Function get_registered_ex Wrap unknown types with a MsgGenerationException.
Function get_special No summary
Function is_special No summary
Function len_serializer_generator Generator for array-length serialization (32-bit, little-endian unsigned integer).
Function make_python_safe Remap field/constant names in spec to avoid collision with Python reserved words.
Function msg_generator Python code generator for .msg files.
Function next_var Undocumented
Function pop_context Pop variable context from context stack.
Function push_context Push new variable context onto context stack.
Function reset_var Undocumented
Function serialize_fn_generator Generator for body of serialize() function.
Function serializer_generator Generator that yields un-indented python code for (de)serializing MsgSpec.
Function simple_serializer_generator Generator (de)serialization code for multiple fields from spec.
Function srv_generator Undocumented
Function string_serializer_generator Generator for string types.
Constant INDENT Undocumented
Function _module_name No summary
Function _remap_reserved Map field_name to a python-safe representation, if necessary.
Constant _SPECIAL_TYPES Undocumented
Variable _context_stack Undocumented
Variable _counter Undocumented
Variable _serial_context Undocumented
def array_serializer_generator(msg_context, package, type_, name, serialize, is_numpy):

Generator for array types.

Raises
Unknown exceptionMsgGenerationException If array spec is invalid
def complex_serializer_generator(msg_context, package, type_, name, serialize, is_numpy):

Generator for serializing complex type.

Parameters
msg_contextUndocumented
packageUndocumented
type_Undocumented
nameUndocumented
serializeif True, generate serialization code. Otherwise, deserialization code. bool
is_numpyif True, generate serializer code for numpy datatypes instead of Python lists, bool
Raises
Unknown exceptionMsgGenerationException If type is not a valid
def compute_constructor(msg_context, package, type_):

Compute python constructor expression for specified message type implementation.

Parameters
msg_contextUndocumented
packageUndocumented
type_message type, str
package strpackage that type is being imported into. Used to resolve type_ if package is not specified. str
def compute_full_text_escaped(msg_context, spec):

Escape the result of genmsg.compute_full_text.

The resulting text is escaped to be safe for Python's triple-quote string quoting.

Parameters
msg_contextUndocumented
specUndocumented
get_deps_dictdictionary returned by load_dependencies call, dict
Returns
concatenated text for msg/srv file and embedded msg/srv types. Text will be escaped for triple-quote, str
def compute_import(msg_context, package, type_):

Compute python import statement for specified message type implementation.

Parameters
msg_contextUndocumented
packagepackage that type is being imported into, str
type_message type (package resource name), str
Returns
list of import statements (no newline) required to use type_ from package, [str]
def compute_outfile_name(outdir, infile_name, ext):
Parameters
outdirUndocumented
infile_nameUndocumented
extUndocumented
outdir strpath to directory that files are generated to
Returns
output file path based on input file name and output directory
def compute_pkg_type(package, type_):
Parameters
packagepackage that type is being imported into, str
type_Undocumented
typemessage type (package resource name), str
Returns
python package and type name, (str, str)
def compute_post_deserialize(type_, varname):

Compute post-deserialization code for type_, if necessary.

Returns
code to execute post-deserialization (unindented), or None if not necessary. str
def compute_resource_name(filename, ext):

Convert resource filename to ROS resource name.

Parameters
filenameUndocumented
extUndocumented
filename strpath to .msg/.srv file
Returns
name of ROS resource
def default_value(msg_context, field_type, default_package):

Compute default value for field_type.

Parameters
msg_contextUndocumented
field_typeROS .msg field type, str
default_packagedefault package, str
Returns
default value encoded in Python string representation, str
def deserialize_fn_generator(msg_context, spec, is_numpy=False):

Generator for body of deserialize() function.

Parameters
msg_contextUndocumented
specUndocumented
is_numpyif True, generate serializer code for numpy datatypes instead of Python lists, bool
def flatten(msg_context, msg):

Flatten the msg spec so that embedded message fields become direct references.

The resulting MsgSpec isn't a true/legal. MsgSpec and should only be used for serializer generation. :param msg: MsgSpec to flatten :returns: flattened MsgSpec message

def get_registered_ex(msg_context, type_):

Wrap unknown types with a MsgGenerationException.

Wrapper for get_registered.

Parameters
msg_contextUndocumented
type_ROS message type, str
def get_special(type_):
Returns
special type handler for type_ or None, Special
def is_special(type_):
Returns
True` if *type_* is a special type (i.e. builtin represented as a class instead of a primitive), ``bool
def len_serializer_generator(var, is_string, serialize):

Generator for array-length serialization (32-bit, little-endian unsigned integer).

Parameters
varvariable name, str
is_stringif True, variable is a string type, bool
serializeUndocumented
serialize boolif True, generate code for serialization. Other, generate code for deserialization, bool
def make_python_safe(spec):

Remap field/constant names in spec to avoid collision with Python reserved words.

Parameters
specmsg spec to map to new, python-safe field names, MsgSpec
Returns
python-safe message specification, MsgSpec
def msg_generator(msg_context, spec, search_path):

Python code generator for .msg files.

Generates a Python from a genmsg.MsgSpec.

Parameters
msg_contextUndocumented
specparsed .msg genmsg.MsgSpec instance
search_pathdictionary mapping message namespaces to a directory locations
def next_var():

Undocumented

def pop_context():

Pop variable context from context stack.

The context stack manages field-reference context for serialization, e.g. 'self.foo' vs. 'self.bar.foo' vs. 'var.foo'

def push_context(context):

Push new variable context onto context stack.

The context stack manages field-reference context for serialization, e.g. 'self.foo' vs. 'self.bar.foo' vs. 'var.foo'

def reset_var():

Undocumented

def serialize_fn_generator(msg_context, spec, is_numpy=False):

Generator for body of serialize() function.

Parameters
msg_contextUndocumented
specUndocumented
is_numpyif True, generate serializer code for numpy datatypes instead of Python lists, bool
def serializer_generator(msg_context, spec, serialize, is_numpy):

Generator that yields un-indented python code for (de)serializing MsgSpec.

The code this yields is meant to be included in a class method and cannot be used standalone. serialize_fn_generator and deserialize_fn_generator wrap method to provide appropriate class field initializations.

Parameters
msg_contextUndocumented
specUndocumented
serializeif True, yield serialization code. Otherwise, yield deserialization code. bool
is_numpyif True, generate serializer code for numpy datatypes instead of Python lists. bool
def simple_serializer_generator(msg_context, spec, start, end, serialize):

Generator (de)serialization code for multiple fields from spec.

Parameters
msg_contextUndocumented
specgenmsg.MsgSpec
startfirst field to serialize, int
endlast field to serialize, int
serializeUndocumented
def srv_generator(msg_context, spec, search_path):

Undocumented

def string_serializer_generator(package, type_, name, serialize):

Generator for string types.

Similar to arrays, but with more efficient call to struct.pack.

Parameters
packageUndocumented
type_Undocumented
namespec field name, str
serializeif True, generate code for serialization. Other, generate code for deserialization, bool
INDENT: str =

Undocumented

Value
'  '
def _module_name(type_name):
Parameters
type_nameUndocumented
type_name strName of message type sans package, e.g. 'String'
Returns
name of python module for auto-generated code
def _remap_reserved(field_name):

Map field_name to a python-safe representation, if necessary.

Parameters
field_namemsg field name, str
Returns
remapped name, str
_SPECIAL_TYPES =

Undocumented

Value
{genmsg.HEADER: Special('std_msgs.msg._Header.Header()',
                        None,
                        'import std_msgs.msg'),
 genmsg.TIME: Special('genpy.Time()', '%s.canon()', 'import genpy'),
 genmsg.DURATION: Special('genpy.Duration()', '%s.canon()', 'import genpy')}
_context_stack: list =

Undocumented

_counter: int =

Undocumented

_serial_context: str =

Undocumented