python中struct.unpack结构指针的解决方法
时间:2008-11-12 来源:mhz-ada
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5C1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><style> </style>
typedef struct _st_DataInfo{
char ReportTime[20];
char GUID[41];
char UserName[33];
char UserIp[50];
int ItemNumber;
DATAITEM *data;
} DATAINFO;
Typedef struct _st_DataItem{
char Infohash[41];
int TotalPeers;
int UploadPeers;
int DownloadPeers;
int StandbyPeers;
long long Upload;
long long Download;
int UploadSpeed;
int DownloadSpeed;
} DATAITEM;
里面的itemnumber是后面DATAITEM结构的个数,而最后的那个DATAITEM *data真是困扰我多时啊,查了半天,也没琢磨出结构指针用哪种format解析,python2.5手册解析格式如下:
|
后来转头一想,算了,把指针长度大小的数据忽略掉吧,四个字节,self.buf = self.buf[:184]+self.buf[188:],后来就成功了
注:谁知道怎么unpack这种的,一定要告诉我啊,多谢了:)