genpy
genpy copied to clipboard
memoryview / buffer inputs should be accepted as serializable data
Let's say I have a large numpy array that represents an std_msgs/Image.data
Today if I try to publish such a message it will fail in this part of the serialize function:
if type(_x) in [list, tuple]:
buff.write(struct.pack('<I%sB'%length, length, *_x))
else:
buff.write(struct.pack('<I%ss'%length, length, _x))
So I would have to to .tostring() or something which will do a copy (and then another copy in struct.pack).
I think that a check should be added if it's a memoryview (py3) or buffer (py2), and then only struct.pack the length, and then simply buff.write the object itself directly.
Please consider to contribute a pull request implementing this feature idea. Please also cover the new functionality with unit tests if you do.