-
Notifications
You must be signed in to change notification settings - Fork 519
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 array behavior #692
Fix array behavior #692
Conversation
Seeing the result, it looks a bit strange, so I'll re-check it. |
Signed-off-by: Kenji Miyake <[email protected]>
Signed-off-by: Kenji Miyake <[email protected]>
Signed-off-by: Kenji Miyake <[email protected]>
Signed-off-by: Kenji Miyake <[email protected]>
Signed-off-by: Kenji Miyake <[email protected]>
Although it's not directly related to this PR, I probably found a mistake. type_map = {
"bool": ["bool"],
"int": ["int8", "byte", "uint8", "char",
"int16", "uint16", "int32", "uint32",
"int64", "uint64", "float32", "float64"],
"float": ["float32", "float64"],
"str": ["string"],
"unicode": ["string"],
"long": ["uint64"]
} It remains until now. rosbridge_suite/rosbridge_library/src/rosbridge_library/internal/message_conversion.py Lines 64 to 65 in cf1beef
@jtbandes Can I remove this here or will you check? -> Removed in https://github.com/RobotWebTools/rosbridge_suite/pull/692/files#r781215355. |
Signed-off-by: Kenji Miyake <[email protected]>
Signed-off-by: Kenji Miyake <[email protected]>
7964eb0
to
06fe1ea
Compare
@@ -61,8 +61,6 @@ | |||
"uint32", | |||
"int64", | |||
"uint64", | |||
"float32", | |||
"float64", |
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.
Since I changed to use type_map["int"]
, I removed them.
https://github.com/RobotWebTools/rosbridge_suite/pull/692/files#diff-212be7c9fa67fbb1f8af9069876e393724e387108a685d2cc0a2f2375b561ddbR253-R254
@@ -91,7 +89,7 @@ | |||
"string", | |||
] | |||
ros_header_types = ["Header", "std_msgs/Header", "roslib/Header"] | |||
ros_binary_types = ["uint8[]", "char[]"] | |||
ros_binary_types = ["uint8[]", "char[]", "sequence<uint8>", "sequence<char>"] |
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.
Since uint8[]
will be sequence<uint8>
, I marked it as binary
.
https://design.ros2.org/articles/idl_interface_definition.html
I think I can drop this, but then sensor_msgs/msg/Image
won't be binary
as well.
https://github.com/ros2/common_interfaces/blob/f41462f5dd36f5c3ae28866f18f356423ffb84e4/sensor_msgs/msg/Image.msg#L26
return inst.tolist() | ||
|
||
if rostype not in type_map.get("float"): | ||
return list(inst) |
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.
Originally, uint32[3]
was converted by list(inst)
, which causes an error here.
It can be checked by the following code.
In [1]: import json
...: import numpy as np
...:
...: json.dumps(list(np.array([1,2,3], dtype=np.uint32)))
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-097c4709dbd2> in <module>
2 import numpy as np
3
----> 4 json.dumps(list(np.array([1,2,3], dtype=np.uint32)))
/usr/lib/python3.8/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder
/usr/lib/python3.8/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
/usr/lib/python3.8/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
/usr/lib/python3.8/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.__class__.__name__} '
180 f'is not JSON serializable')
181
TypeError: Object of type uint32 is not JSON serializable
except Exception: | ||
if isinstance(msg, str): | ||
return list(standard_b64decode(msg)) | ||
if isinstance(msg, list): |
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.
If we accept list
input like this, we need this if-condition.
# Only bother sending the log message if there's an id | ||
self.log("error", "Unable to serialize %s message to client" % msg["op"], cid) | ||
except Exception as e: | ||
self.log("error", f"Unable to serialize message '{msg}': {e}") |
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.
Without this, I think we can't notice the errors. This time it took a lot of time to find the cause. 🥺
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.
interesting - why would cid
be None?
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.
Mm, sorry I'm not sure about that. 😢
@jtbandes I'm done! Could you review this, please? 🙏 |
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.
Sorry for the delay – Thanks for fixing this! It would be nice to add some integration tests too, to prove it's working as expected end to end.
# Only bother sending the log message if there's an id | ||
self.log("error", "Unable to serialize %s message to client" % msg["op"], cid) | ||
except Exception as e: | ||
self.log("error", f"Unable to serialize message '{msg}': {e}") |
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.
interesting - why would cid
be None?
Public API Changes
uint8[]
will be sent inbinary
format instead oflist
format.Description
Split from #646.
Fixed the behavior around arrays.
How to test
Fixed Array
Before(upstream/ros2)
After(this PR)
Multi Array
Before(upstream/ros2)
This means
uint8[]
such as insensor_msgs/msg/Image
won't bebinary
.https://github.com/ros2/common_interfaces/blob/f41462f5dd36f5c3ae28866f18f356423ffb84e4/sensor_msgs/msg/Image.msg#L26
https://github.com/ros2/example_interfaces/blob/2977bbe4e5e30c74d3594d31a8212193f5c27761/msg/UInt8MultiArray.msg#L9
After(this PR)
uint32[3] (#699)
Before(upstream/ros2)
After(this PR)