-1

I get the warning

Incompatable ponter type 'uint8_t *' send to 'uint8_t **'

when passing value to parameter 'buffer' in below method in NSStream class

- (BOOL)getBuffer:(uint8_t **)buffer length:(NSUInteger *)len;

Below is the code I am using. 'fileStream' is 'NSInputStream' instant object

    uint8_t oneByte;
[fileStream read: &oneByte maxLength: 1];
NSUInteger* remaining = 0;
[fileStream getBuffer: &oneByte length:remaining];
  • tried `uint8_t *oneByte;`? :) – geo Nov 11 '13 at 14:27
  • While using *oneByte operation failed in below method - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len . My code uint8_t *oneByte = NULL; [fileStream read: oneByte maxLength: 1]; (using &oneByte gives warning now. So used oneByte) – Afsal Meerankutty Nov 11 '13 at 14:37

1 Answers1

2

It appears from the signature that the method does not want you to allocate space for the buffer, or pass the length: it will return a pointer to an existing buffer, and set the length of that buffer to the NSUInteger pointer that you pass, like this:

uint8_t *buf;
NSUInteger len;
[fileStream getBuffer:&buf length:&len];
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • While using *oneByte operation failed in below method - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len My code uint8_t *oneByte = NULL; [fileStream read: oneByte maxLength: 1]; (using &oneByte gives warning now. So used oneByte) – Afsal Meerankutty Nov 11 '13 at 14:38
  • @AfsalMeerakutty The `read:maxLength:` method has a different signature than `getBuffer:length:`. You shouldn't be using the same parameters in these two calls - the first one needs you to allocate a buffer, while the second one gives the buffer back to you. – Sergey Kalinichenko Nov 11 '13 at 14:43
  • thank you dasblinkenlight. I misunderstood the method to get length of buffer already read by the read method. How can I get remaining data from stream after reading part of it? I want to know this because currently - (BOOL)hasBytesAvailable in NSInputSream is returning me false after reading 112th line in my text file – Afsal Meerankutty Nov 11 '13 at 14:57
  • @AfsalM The most common approach is to call `read:maxLength:` method in a loop until it returns zero. Since this is a file stream, it wouldn't block when no data is available (that's more useful for socket streams). – Sergey Kalinichenko Nov 11 '13 at 15:11