[英]JNA: How can I define a structure with fields of custom bit sizes?
例如,我有以下C ++结构......
struct dleaf_t
{
int contents; // OR of all brushes (not needed?)
short cluster; // cluster this leaf is in
short area : 9; // area this leaf is in
short flags : 7; // flags
short mins[ 3 ]; // for frustum culling
short maxs[ 3 ];
unsigned short firstleafface; // index into leaffaces
unsigned short numleaffaces;
unsigned short firstleafbrush; // index into leafbrushes
unsigned short numleafbrushes;
short leafWaterDataID; // -1 for not in water
//!!! NOTE: for maps of version 19 or lower uncomment this block
/*
CompressedLightCube ambientLighting; // Precaculated light info for entities.
short padding; // padding to 4-byte boundary
*/
};
通常我可以使用JNA在Java中轻松地表示结构,但是这种结构对数据类型使用自定义位数(如果我没有记错的话)。
例如, area
是9位的short
,而不是通常的16位。 flags
是7位......等等。
如何使用自定义位大小的数据类型定义JNA结构?
将两个位字段合并为单个int
字段,然后编写成员方法以提取已合并的各个字段的值,例如
public int area_flags;
public int getArea() { return area_flags & 0x1FF; }
public int getFlags() { return (area_flags >> 9) & 0x3F; }
根据编译器打包位的方式,您可能需要稍微改变一下。
我不知道JNA是否可行。 请查看文档,看看是否可以找到有关您的问题的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.