开发者

NSMakeRange - replaceBytesInRange Question

开发者 https://www.devze.com 2023-01-25 13:08 出处:网络
In the following code I get the expected results - (int)getInt{ NSRange intRange = NSMakeRange(0,3); char buffer[4];

In the following code I get the expected results

- (int)getInt{
 NSRange intRange = NSMakeRange(0,3);

 char buffer[4];
 [stream getBytes:buffer range:intRange];

 [stream replaceBytesInRange:NSMakeRange(0, 3) withBytes:NULL length:0];

 return (int) (
      (((int)buffer[0] & 开发者_JS百科0xffff) << 24) |
      (((int)buffer[1] & 0xffff) << 16) |
      (((int)buffer[2] & 0xffff) << 8) |
       ((int)buffer[3] & 0xffff) );


}

If I change intRange to 0, 4 I get the expected results.

If I change replaceBytesInRange to 0, 4 I seem to loose an extra byte in the stream.

I'm okay with using 0,3 - but I'm wondering why this happens, because with 2 and 8 byte replacements I do not get this behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消