Copy the entire byte array instead of iterating over one byte at a time. This makes CBOR much much faster at encoding messages with large binary blobs.
Benchmarking on this data, a ROS2 sensor_msgs/Image of 640x480 RGB:
Coverage increased (+0.003%) to 99.265% when pulling 1a6de156903322c39734c613def5f19e00d1a934 on mvollrath:fast_byte_array_encoding into 65dc49611107db83aff8308a6b381f4d7933824b on paroga:master.
Copy the entire byte array instead of iterating over one byte at a time. This makes CBOR much much faster at encoding messages with large binary blobs.
Benchmarking on this data, a ROS2 sensor_msgs/Image of 640x480 RGB:
master
CBOR encode: 20.234ms
fast_byte_array_encoding
CBOR encode: 1.288ms