![](/img/trans.png)
[英]How to use struct.unpack and convert it to a value in Objective-c
[英]convert struct.unpack from python to objective-c?
我将以下Python代码从PDFMiner复制到Objective-C:
(name, tsum, offset, length) = struct.unpack('>4sLLL', fp.read(16))
这就是我所拥有的:
unsigned char characters[5];
[stream getBytes:characters range:NSMakeRange(position, 4)];
position+=4;
characters[4] = 0;
NSString* name = [NSString stringWithFormat:@"%s", characters];
unsigned long tsum;
[stream getBytes:&tsum range:NSMakeRange(position, 4)];
position+=4;
unsigned long offset;
[stream getBytes:&offset range:NSMakeRange(position, 4)];
position+=4;
unsigned long length;
[stream getBytes:&length range:NSMakeRange(position, 4)];
position+=4;
名称已正确读取,但tsum,offset和length却未正确读取。 知道为什么这可能行不通吗?
我怀疑有填充字节,但我不确定在哪里。 L代表无符号的长时间,所以我怀疑这就是问题所在
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.