serialize memoryview
Posted: Mon Jan 18, 2021 3:19 am
I'm working on an msgpack serializer for micropython written in C.
Python bytes objects map to the msgpack bin type and serializing those works fine.
Now I would like the packer also to handle memoryviews of bytes (and bytearray) objects and wonder how to do this. Memoryviews are defined in in py/objarray.[hc]. One option is to detect memoryviews with type BYTEARRAY_TYPECODE or MICROPY_PY_BUILTINS_BYTEARRAY and then directly access the mp_obj_array_t.
It this the correct approach or does a more appropriate api exist?
Python bytes objects map to the msgpack bin type and serializing those works fine.
Now I would like the packer also to handle memoryviews of bytes (and bytearray) objects and wonder how to do this. Memoryviews are defined in in py/objarray.[hc]. One option is to detect memoryviews with type BYTEARRAY_TYPECODE or MICROPY_PY_BUILTINS_BYTEARRAY and then directly access the mp_obj_array_t.
It this the correct approach or does a more appropriate api exist?