julia如何读取二进制的结构体文件


#1

分析C语言保存的二进制结构体文件,结构体有可能被指定了内存对齐字节数,如何用julia将这样的文件按结构体读出,julia的struct是否支持内存对齐

比如用C语言往文件里保存了多个下面这样的结构体,按单字节对齐的:
#pragma pack(push, 1)
struct A
{
char bb[11];
integer cc ;
double dd;
};
#pragma pack(pop)

在julia里如何每次读出一个完整的结构体,并且保证结构体成员获得正确的数值


#2

一次读一个结构体我没找到好用的包/函数。

看其它包(UCSF.jl)是先定义结构体,再用 readbytes! + reinterpret 读取。

对齐可以考虑加保留字段手工对齐 or 读取的时候读一下就跳过空隙。


#3

今天看见一个用 DataStructures: OrderedDict 定义结构体然后读的


#4

doc:

When used recursively, isbits types are stored inline. All other types are stored as a pointer to the data. When mirroring a struct used by-value inside another struct in C, it is imperative that you do not attempt to manually copy the fields over, as this will not preserve the correct field alignment. Instead, declare an isbits struct type and use that instead. Unnamed structs are not possible in the translation to Julia.

Packed structs and union declarations are not supported by Julia.