Package roslib :: Module genpy
[frames] | no frames]

Module genpy

source code

Library for Python message generation.

The structure of the serialization descends several levels of serializers:

Classes
  MsgGenerationException
Exception type for errors in roslib.genpy
  Special
Functions
 
get_registered_ex(type_)
wrapper for roslib.msgs.get_registered that wraps unknown types with a MsgGenerationException
source code
bool
is_simple(type_) source code
bool
is_special(type_)
@return True if type_ is a special type (i.e.
source code
Special
get_special(type_)
Returns: special type handler for type_ or None
source code
str
default_value(field_type, default_package)
Compute default value for field_type
source code
MsgSpec
flatten(msg)
Flattens the msg spec so that embedded message fields become direct references.
source code
MsgSpec
make_python_safe(spec)
Remap field/constant names in spec to avoid collision with Python reserved words.
source code
str
compute_struct_pattern(types)
Returns: format string for struct if types are all simple.
source code
str
compute_post_deserialize(type_, varname)
Compute post-deserialization code for type_, if necessary
source code
 
compute_constructor(package, type_)
Compute python constructor expression for specified message type implementation
source code
 
compute_pkg_type(package, type_) source code
[str]
compute_import(package, type_)
Compute python import statement for specified message type implementation
source code
str
compute_full_text_escaped(gen_deps_dict)
Same as roslib.gentools.compute_full_text, except that the resulting text is escaped to be safe for Python's triple-quote string quoting
source code
str
reduce_pattern(pattern)
Optimize the struct format pattern.
source code
 
serialize(expr) source code
 
int32_pack(var)
Returns: struct packing code for an int32
source code
 
int32_unpack(var, buff)
Returns: struct unpacking code for an int32
source code
 
pack(pattern, vars)
create struct.pack call for when pattern is a string pattern
source code
 
pack2(pattern, vars)
create struct.pack call for when pattern is the name of a variable
source code
 
unpack(var, pattern, buff)
create struct.unpack call for when pattern is a string pattern
source code
 
unpack2(var, pattern, buff)
Create struct.unpack call for when pattern refers to variable
source code
 
unpack_numpy(var, count, dtype, buff)
create numpy deserialization code
source code
 
pack_numpy(var)
create numpy serialization code
source code
 
next_var() source code
 
push_context(context)
Push new variable context onto context stack.
source code
 
pop_context()
Pop variable context from context stack.
source code
 
add_pattern(p)
Record struct pattern that's been used for (de)serialization
source code
 
clear_patterns()
Clear record of struct pattern that have been used for (de)serialization
source code
 
get_patterns()
Returns: record of struct pattern that have been used for (de)serialization
source code
 
len_serializer_generator(var, is_string, serialize)
Generator for array-length serialization (32-bit, little-endian unsigned integer)
source code
 
string_serializer_generator(package, type_, name, serialize)
Generator for string types.
source code
 
array_serializer_generator(package, type_, name, serialize, is_numpy)
Generator for array types
source code
 
complex_serializer_generator(package, type_, name, serialize, is_numpy)
Generator for serializing complex type
source code
 
simple_serializer_generator(spec, start, end, serialize)
Generator (de)serialization code for multiple fields from spec
source code
 
serializer_generator(package, spec, serialize, is_numpy)
Python generator that yields un-indented python code for (de)serializing MsgSpec.
source code
 
serialize_fn_generator(package, spec, is_numpy=False)
generator for body of serialize() function
source code
 
deserialize_fn_generator(package, spec, is_numpy=False)
generator for body of deserialize() function
source code
 
msg_generator(package, name, spec)
Python code generator for .msg files.
source code
 
generate_dynamic(core_type, msg_cat)
Dymamically generate message classes from msg_cat .msg text gendeps dump.
source code
Variables
  INDENT = ' '
  SIMPLE_TYPES_DICT = {'bool': 'B', 'byte': 'b', 'char': 'B', 'f...
  SIMPLE_TYPES = ['int32', 'int16', 'uint8', 'char', 'byte', 'in...
  __package__ = 'roslib'
Function Details

get_registered_ex(type_)

source code 

wrapper for roslib.msgs.get_registered that wraps unknown types with a MsgGenerationException

Parameters:
  • type_ (str) - ROS message type

is_special(type_)

source code 

@return True if type_ is a special type (i.e. builtin represented as a class instead of a primitive)

Returns: bool

get_special(type_)

source code 
Returns: Special
special type handler for type_ or None

default_value(field_type, default_package)

source code 

Compute default value for field_type

Parameters:
  • default_package (str) - default package
  • field_type (ROS .msg field type), str - ROS .msg field type
Returns: str
default value encoded in Python string representation

flatten(msg)

source code 

Flattens 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

Parameters:
  • msg (MsgSpec) - msg to flatten
Returns: MsgSpec
flatten message

make_python_safe(spec)

source code 

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

Parameters:
  • spec (MsgSpec) - msg spec to map to new, python-safe field names
Returns: MsgSpec
python-safe message specification

compute_struct_pattern(types)

source code 
Parameters:
  • types ([str]) - type names
Returns: str
format string for struct if types are all simple. Otherwise, return None

compute_post_deserialize(type_, varname)

source code 

Compute post-deserialization code for type_, if necessary

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

compute_constructor(package, type_)

source code 

Compute python constructor expression for specified message type implementation

Parameters:
  • package (str), str - package that type is being imported into. Used to resolve type_ if package is not specified.
  • type_ (str) - message type

compute_pkg_type(package, type_)

source code 
Parameters:
  • package (str) - package that type is being imported into
  • type (str) - message type (package resource name)

compute_import(package, type_)

source code 

Compute python import statement for specified message type implementation

Parameters:
  • package (str) - package that type is being imported into
  • type_ (str) - message type (package resource name)
Returns: [str]
list of import statements (no newline) required to use type_ from package

compute_full_text_escaped(gen_deps_dict)

source code 

Same as roslib.gentools.compute_full_text, except that the resulting text is escaped to be safe for Python's triple-quote string quoting

Parameters:
  • get_deps_dict (dict) - dictionary returned by get_dependencies call
Returns: str
concatenated text for msg/srv file and embedded msg/srv types. Text will be escaped for triple-quote

reduce_pattern(pattern)

source code 

Optimize the struct format pattern.

Parameters:
  • pattern (str) - struct pattern
Returns: str
optimized struct pattern

int32_pack(var)

source code 
Parameters:
  • var (str) - variable name
Returns:
struct packing code for an int32

int32_unpack(var, buff)

source code 
Parameters:
  • var (str) - variable name
Returns:
struct unpacking code for an int32

pack(pattern, vars)

source code 

create struct.pack call for when pattern is a string pattern

Parameters:
  • pattern (str) - pattern for pack
  • vars (str) - name of variables to pack

pack2(pattern, vars)

source code 

create struct.pack call for when pattern is the name of a variable

Parameters:
  • pattern (struct) - name of variable storing string pattern
  • vars (str) - name of variables to pack

unpack(var, pattern, buff)

source code 

create struct.unpack call for when pattern is a string pattern

Parameters:
  • var (str) - name of variable to unpack
  • pattern (str) - pattern for pack
  • buff (str) - buffer to unpack from

unpack2(var, pattern, buff)

source code 

Create struct.unpack call for when pattern refers to variable

Parameters:
  • var (str) - variable the stores the result of unpack call
  • pattern (str) - name of variable that unpack will read from
  • buff (StringIO) - buffer that the unpack reads from

pack_numpy(var)

source code 

create numpy serialization code

Parameters:
  • vars - name of variables to pack

push_context(context)

source code 

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'

pop_context()

source code 

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'

get_patterns()

source code 
Returns:
record of struct pattern that have been used for (de)serialization

len_serializer_generator(var, is_string, serialize)

source code 

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

Parameters:
  • var (str) - variable name
  • is_string (bool) - if True, variable is a string type
  • serialize (bool), bool - if True, generate code for serialization. Other, generate code for deserialization

string_serializer_generator(package, type_, name, serialize)

source code 

Generator for string types. similar to arrays, but with more efficient call to struct.pack.

Parameters:
  • name (str) - spec field name
  • serialize (bool) - if True, generate code for serialization. Other, generate code for deserialization

array_serializer_generator(package, type_, name, serialize, is_numpy)

source code 

Generator for array types

Raises:

complex_serializer_generator(package, type_, name, serialize, is_numpy)

source code 

Generator for serializing complex type

Parameters:
  • serialize (bool) - if True, generate serialization code. Otherwise, deserialization code.
  • is_numpy (bool) - if True, generate serializer code for numpy datatypes instead of Python lists
Raises:

simple_serializer_generator(spec, start, end, serialize)

source code 

Generator (de)serialization code for multiple fields from spec

Parameters:
  • spec (MsgSpec) - MsgSpec
  • start (int) - first field to serialize
  • end (int) - last field to serialize

serializer_generator(package, spec, serialize, is_numpy)

source code 

Python 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:
  • package (str) - name of package the spec is being used in
  • serialize (bool) - if True, yield serialization code. Otherwise, yield deserialization code.
  • is_numpy (bool) - if True, generate serializer code for numpy datatypes instead of Python lists

serialize_fn_generator(package, spec, is_numpy=False)

source code 

generator for body of serialize() function

Parameters:
  • is_numpy (bool) - if True, generate serializer code for numpy datatypes instead of Python lists

deserialize_fn_generator(package, spec, is_numpy=False)

source code 

generator for body of deserialize() function

Parameters:
  • is_numpy (bool) - if True, generate serializer code for numpy datatypes instead of Python lists

msg_generator(package, name, spec)

source code 

Python code generator for .msg files. Takes in a package name, message name, and message specification and generates a Python message class.

Parameters:
  • package (str) - name of package for message
  • name (str) - base type name of message, e.g. 'Empty', 'String'
  • spec (MsgSpec) - parsed .msg specification

generate_dynamic(core_type, msg_cat)

source code 

Dymamically generate message classes from msg_cat .msg text gendeps dump. This method modifies sys.path to include a temp file directory.

Parameters:
  • core_type, str - top-level ROS message type of concatenanted .msg text
  • msg_cat, str - concatenation of full message text (output of gendeps --cat)
Raises:

Variables Details

SIMPLE_TYPES_DICT

Value:
{'bool': 'B',
 'byte': 'b',
 'char': 'B',
 'float32': 'f',
 'float64': 'd',
 'int16': 'h',
 'int32': 'i',
 'int64': 'q',
...

SIMPLE_TYPES

Value:
['int32',
 'int16',
 'uint8',
 'char',
 'byte',
 'int8',
 'uint64',
 'float64',
...