我正在使用python构造函数(第3个库),并且试图在结构体内部使用结构体,就像在C#中一样。示例(C#):
BlogPosts
在python中,我正在尝试通过以下方式进行操作:
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi, Size = 12)]
public struct pHeader
{
public ushort size;
public byte key;
public byte checksum;
public ushort packetId;
public ushort clientId;
public uint timestamp;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct p333Chat
{
public pHeader _header;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 96)]
public byte[] texto;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
byte[] unknown;
}
这就是我要构建的方式:
self.Header = Struct(
'size' / Int16ub,
'key' / Int8ub,
'checksum' / Int8ub,
'packetId' / Int16ub,
'clientId' / Int16ub,
'timestamp' / Int32ub,
)
#p20D login
self.P20D_Login = Struct(
"header" / self.Header,
"teste" / Int16ub
)
但是它不起作用,有人知道这样做的方法吗?