genpy icon indicating copy to clipboard operation
genpy copied to clipboard

memoryview / buffer inputs should be accepted as serializable data

Open tzickel opened this issue 5 years ago • 1 comments

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.

tzickel avatar Aug 28 '19 16:08 tzickel

Please consider to contribute a pull request implementing this feature idea. Please also cover the new functionality with unit tests if you do.

dirk-thomas avatar Aug 28 '19 17:08 dirk-thomas