【发布时间】:2019-05-05 02:42:46
【问题描述】:
我有一个 32 位无符号整数的内存视图,我想将其解压缩成一些字符、整数和字符串(或必要时的字符数组)。
cdef const unsigned int[:] bin_file = np.fromfile(rom_fd, dtype='<u4')
此二进制文件的前 192 个字节用作包含有关文件其余部分的元数据的标头。
我想从 memoryview(或 memoryviewslice:bin_file[:48])中解压这些字节
从 memoryview 中获取 int 很容易:
cdef unsigned int first_int = bin_file[0]
但是,我不确定获取其他数据类型的最佳方式,尤其是那些跨越内存视图中多个条目的数据类型。
我希望能够使用类似的东西
cdef char[12] my_string = bin_file[40:43]
但这只会给出错误提示“无法将类型 'const unsigned int[:]' 分配给 'char [12]'”。
【问题讨论】:
标签: python cython binaryfiles memoryview