fix(set_message): encode strings if field is bytes#30
fix(set_message): encode strings if field is bytes#30russkel wants to merge 3 commits intoros2:rollingfrom
Conversation
ac20f17 to
faf19f3
Compare
|
If this could be backported to jazzy that would be lovely too. |
faf19f3 to
6670ff4
Compare
Signed-off-by: Russ Webber <russ.webber@greenroomrobotics.com>
6670ff4 to
9483332
Compare
fujitatomoya
left a comment
There was a problem hiding this comment.
looks good to me but i would like to have 2nd review just in case something missing.
|
Pulls: #30 |
0c3c97c to
ee6c327
Compare
Signed-off-by: Russ Webber <russ.webber@greenroomrobotics.com>
ee6c327 to
ad5a8b2
Compare
|
I added a basic smoke test for conversion from yaml using one of the test message fixtures and it appears not good enough with a string containing In [1]: moo = '\xff'
In [2]: moo
Out[2]: 'ÿ'
In [3]: moo.encode()
Out[3]: b'\xc3\xbf'
In [9]: moo = chr(0xff)
In [10]: moo
Out[10]: 'ÿ'
In [11]: moo.encode(encoding='utf8')
Out[11]: b'\xc3\xbf'
In [12]: moo.encode(encoding='utf16')
Out[12]: b'\xff\xfe\xff\x00'
In [13]: moo.encode(encoding='ascii')
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
Cell In[13], line 1
----> 1 moo.encode(encoding='ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xff' in position 0: ordinal not in range(128)
In [17]: for c in moo: print(ord(c))
255
In [19]: import yaml
In [20]: yaml.dump('\xff')
Out[20]: '"\\xFF"\n'
In [21]: from rosidl_runtime_py.convert import _convert_value
In [22]: _convert_value('\xff')
Out[22]: 'ÿ'
In [27]: bytes(moo, 'ascii', 'backslashreplace')
Out[27]: b'\\xff'
|
|
The only way I am able to get this to pass is using |
|
Does passing |
I was trying to load yaml that was output from
ros2 topic echoand then convert them back into msgs for fixtures, and I came across this issue:With the following yaml:
The
levelvalue is a string\x02butset_messageis trying to convert it to thefield_typebytes. This patch fixes this issue by encoding the string to bytes.