I have some binary data which has a corresponding "map" file which identifies each data point in the binary data by providing a bit offset and length. So, I might have the following mappings:
$paths = array ( "path1" => array ("offset" => 224, "size" => 2),
"path2" => array ("offset" => 226, "size" => 6),
);
In actuality I have tens of thousands of these paths to offset/size mappings. Now, given a path I want to be able to seek to the appropriate offset and read the number of bits as given by size. In this simple case, path1 and path2 represent a single byte where path1 is the first 2 bits and path2 are the last 6 bits.
I have already written this in Python and am now porting over the code to PHP for reasons I won't go into :)
Anyway, for whole bytes sizes at whole byte offsets I can just use unpack with the appropriate format string. What I have a problem with is how to handle these "oddly" sized sets of bits.
The only way I have thought of thus far would be finding the nearest bit offset where the offset modulus 8 gives 0 (whole byte) and is less than the given offset, then find the smallest size (again in whole byte sizes) from this new offset which encompasses all of the required bits, then use a bitwise & to mask the bits I want.
In Python I could just use the bitbuffer module which let me seek to a bit offset, then read any number of bits I wanted. Anything like this in the PHP world?
Thanks.