Skip to content

Commit

Permalink
Merge pull request #19 from ros/list_time_int_or_long
Browse files Browse the repository at this point in the history
enable int/long values for list of time/duration (fix #13)
  • Loading branch information
dirk-thomas committed Aug 16, 2013
2 parents d09681f + b77e99a commit 4433d99
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/genpy/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,17 @@ def _fill_val(msg, f, v, keys, prefix):
del def_val[:]
for el in v:
inner_msg = list_msg_class()
_fill_message_args(inner_msg, el, prefix)
if isinstance(inner_msg, TVal) and type(el) in (int, long):
#special case to handle time value represented as a single number
#TODO: this is a lossy conversion
if isinstance(inner_msg, Time):
inner_msg = Time.from_sec(el/1e9)
elif isinstance(inner_msg, Duration):
inner_msg = Duration.from_sec(el/1e9)
else:
raise MessageException("Cannot create time values of type [%s]"%(type(inner_msg)))
else:
_fill_message_args(inner_msg, el, prefix)
def_val.append(inner_msg)
else:
setattr(msg, f, v)
Expand Down

0 comments on commit 4433d99

Please sign in to comment.