question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot/don't know how to publish message with `byte[]` field

See original GitHub issue

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • ros2cli 0.13.4
  • DDS implementation:
    • rmw_cyclonedds_cpp: 0.22.5
  • Client library (if applicable):
    • N/A

Steps to reproduce issue

Trying to ros2 topic pub a std_msgs/msg/ByteMultiArray message. I have tried:

bash ros2 topic pub -1 /whatever std_msgs/msg/ByteMultiArray "{data: [{3}, {4}]}"

and

bash ros2 topic pub -1 /whatever std_msgs/msg/ByteMultiArray "{data: [0x03, 0x04]}" 

Expected behavior

Successful publishing.

Actual behavior

Error response:

Failed to populate field: The 'data' field must be a set or sequence and each value of type 'bytes'

Additional information

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
iuhilnehc-ynoscommented, Sep 13, 2022

@fujitatomoya

The generated message for python in build/std_msgs/ament_cmake_python/std_msgs/std_msgs/msg/_byte_multi_array.py:158 only checking a type bytes seems not enough.

            assert \
                ((isinstance(value, Sequence) or
                  isinstance(value, Set) or
                  isinstance(value, UserList)) and
                 not isinstance(value, str) and
                 not isinstance(value, UserString) and
                 all(isinstance(v, bytes) for v in value) and
                 True), \
                "The 'data' field must be a set or sequence and each value of type 'bytes'"
        self._data = value

The type could be int if using ros2 topic pub -1 /whatever std_msgs/msg/ByteMultiArray "{data: [3]}".

I am afraid that we should update the above source code with

            assert \
                ((isinstance(value, Sequence) or
                  isinstance(value, Set) or
                  isinstance(value, UserList)) and
                 not isinstance(value, str) and
                 not isinstance(value, UserString) and
                 all((isinstance(v, bytes) or isinstance(v, int)) for v in value) and
                 True), \
                "The 'data' field must be a set or sequence and each value of type 'bytes'"
        if any(isinstance(v, int) for v in value):
            self._data = bytearray(value)
        else:
            self._data = value

NOTE: It means that we need to update https://github.com/ros2/rosidl_python/blob/52e099efef21366ff651385da865e305228d24ec/rosidl_generator_py/resource/_msg.py.em

0reactions
fujitatomoyacommented, Sep 13, 2022
root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub -1 /whatever std_msgs/msg/Byte "\!\!binary 'Aw=='"
The passed value needs to be a dictionary in YAML format
root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 topic pub -1 /whatever std_msgs/msg/Byte "\!\!binary 'AwQ='"
The passed value needs to be a dictionary in YAML format

both do not work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Try-Me seems to send message as byte[] array and not text
Hi,. Using the the try-me functionality of the Solace Cloud Console to publish a message. The problem is that it seems to sends...
Read more >
in JMeter, how to send a 4 byte message to a JMS publisher
I have to run a performance test on a application that consumes from a ActiveMQ topic. The sampler needs to publish 4 Bytes...
Read more >
Understanding of AMQP Basic.Publish frame format
I am trying to parse the "arguments" field in the payload of AMQP Basic.Publish method According to the specifications, the three first parameters...
Read more >
Publish - Amazon Simple Notification Service
Sends a message to an Amazon SNS topic, a text message (SMS message) ... You can publish messages only to topics and endpoints...
Read more >
Understanding the MQTT Protocol Packet Structure
The minimum size of the packet length field is 1 byte which is for messages with a total length less than 127 bytes.(not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found