4 from cStringIO
import StringIO
6 from io
import StringIO
22 'string':
'::std::string::String',
30 Creates a list of unique packages based on dependencies 33 for field
in spec.parsed_fields():
34 if (
not field.is_builtin):
36 packages.append(
'std_msgs')
39 name) = genmsg.names.package_resource_name(field.base_type)
40 packages.append((package
or spec.package) +
' ' +
47 Converts a message type (e.g. uint32, std_msgs/String, etc.) into the Rust declaration 48 for that type (e.g. u32, std_msgs.String) 50 @param type: The message type 52 @return: The Rust declaration 55 (base_type, is_array, array_len) = genmsg.msgs.parse_type(type)
57 if (genmsg.msgs.is_builtin(base_type)):
58 rs_type = MSG_TYPE_TO_RS[base_type]
59 elif (len(base_type.split(
'/')) == 1):
60 if (genmsg.msgs.is_header_type(base_type)):
61 rs_type =
'super::std_msgs::Header' 65 pkg = base_type.split(
'/')[0]
66 msg = base_type.split(
'/')[1]
67 rs_type =
'super::%s::%s' % (pkg, msg)
71 return 'Vec<%s>' % (rs_type)
73 return '(%s)' % (
', '.join([rs_type
for _
in range(array_len)]))
80 Returns the value to initialize a message member with. 82 0 for integer types and times, 83 0.0 for floating point, 85 default string for string, 86 ::new() for everything else 91 (base_type, is_array, array_len) = genmsg.msgs.parse_type(type)
92 if is_array
and array_len
is None:
97 'byte',
'int8',
'int16',
'int32',
'int64',
'char',
'uint8',
98 'uint16',
'uint32',
'uint64',
'time',
'duration' 100 rs_def =
'0' + rs_type
101 elif base_type
in [
'float32',
'float64']:
102 rs_def =
'0.0' + rs_type
103 elif base_type ==
'bool':
105 elif base_type ==
'string':
106 rs_def =
'::std::string::String::new()' 108 rs_def = rs_type +
'::new()' 109 if is_array
and array_len
is not None:
110 return '(%s)' % (
', '.join([rs_def
for _
in range(array_len)]))
116 s = s.replace(
'\\',
'\\\\')
117 s = s.replace(
'"',
'\\"')
122 lines = definition.splitlines()
128 s.write(
'%s\\n\\\n' % (line))
def escape_message_definition(definition)
def default_value(type, package)
def msg_type_to_rs(type, package)