我需要读取包含此结构的二进制文件:
struct iqmheader
{
char magic[16]; // the string "INTERQUAKEMODEL\0", 0 terminated
uint version; // must be version 2
uint filesize;
uint flags;
uint num_text, ofs_text;
uint num_meshes, ofs_meshes;
uint num_vertexarrays, num_vertexes, ofs_vertexarrays;
uint num_triangles, ofs_triangles, ofs_adjacency;
uint num_joints, ofs_joints;
uint num_poses, ofs_poses;
uint num_anims, ofs_anims;
uint num_frames, num_framechannels, ofs_frames, ofs_bounds;
uint num_comment, ofs_comment;
uint num_extensions, ofs_extensions;
};
有没有一种优雅的方式来做到这一点?我以这种方式尝试了 javolution lib:
import javolution.io.Struct;
import java.nio.ByteOrder;
public class IqmHeader extends Struct {
public final UTF8String magic = new UTF8String(16);
public final Unsigned8 version = new Unsigned8();
public final Unsigned8 filesize = new Unsigned8();
}
前 2 个值(魔法值和版本)是正确的,但对于第三个值,我已经得到 0,这是错误的。
使用十六进制编辑器打开的文件(第一个字节,不是整个文件):
这是十六进制编辑器的输出:
49 4E 54 45 52 51 55 41 4B 45 4D 4F 44 45 4C 00 02 00 00 00 10 EF 03 00 00 00 00 00 60 03 00 00 7C 00 00 00 02 00 00 00 DC 03 00 00 06 00 00 00 45 07 00 00 0C 04 00 00 AC 0B 00 00 A0 9B 01 00 B0 27 02 00 4B 00 00 00 C0 B3 02 00 4B 00 00 00 D0 C1 02 00 01 00 00 00 98 DB 02 00 65 00 00 00 4D 01 00 00 AC DB 02 00 70 E2 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 6F 64
我必须承认我真的不知道如何阅读这个。前 16 个字节是后面跟着“00”的字符串。然后是版本“02”-在这里我不知道 uint 需要多少字节
有什么建议么?