user2444342
user2444342

Reputation: 159

convert struct.unpack from python to objective-c?

I’m copying this python code from PDFMiner into 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. Any idea why this might not work?

Upvotes: 0

Views: 82

Answers (1)

Nate Krito
Nate Krito

Reputation: 56

I suspect there's padding bytes, but I'm not sure where. L stands for unsigned long so I doubt that's the problem

Upvotes: 1

Related Questions