-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(set_message): encode strings if field is bytes #30
base: rolling
Are you sure you want to change the base?
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 <[email protected]>
6670ff4
to
9483332
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
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 echo
and then convert them back into msgs for fixtures, and I came across this issue:With the following yaml:
The
level
value is a string\x02
butset_message
is trying to convert it to thefield_type
bytes
. This patch fixes this issue by encoding the string to bytes.