[英]convert struct.unpack from python to objective-c?
I'm copying this python code from PDFMiner into objective-c: 我将以下Python代码从PDFMiner复制到Objective-C:
(name, tsum, offset, length) = struct.unpack('>4sLLL', fp.read(16))
This is what I have: 这就是我所拥有的:
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;
The name is read correctly, but the tsum, offset, and length are read incorrectly. 名称已正确读取,但tsum,offset和length却未正确读取。 Any idea why this might not work?
知道为什么这可能行不通吗?
I suspect there's padding bytes, but I'm not sure where. 我怀疑有填充字节,但我不确定在哪里。 L stands for unsigned long so I doubt that's the problem
L代表无符号的长时间,所以我怀疑这就是问题所在
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.