Native object exposing buffer protocol

Rob Gaddi rgaddi at highlandtechnology.invalid
Fri Jan 5 19:01:50 EST 2018


I'd like to create a native Python object that exposes the buffer 
protocol.  Basically, something with a ._data member which is a 
bytearray that I can still readinto, make directly into a numpy array, etc.

I can do it by inheriting the entire thing from bytearray directly, but 
that gives me a whole lot of methods that are unsuitable for what I'm 
doing with it, which is reading the contents of a binary file, allowing 
them to be lightly malleable in memory, and then sending them on to a 
device.

Not the end of the world (the file's less than 2KB), but it seems like 
something that should be doable easily without having to throw around a 
lot of extraneous copies.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list