What is the best way to implement a Java-like ByteBuffer in Obj-C?

I am trying to create an iPhone app, although I am completely new to Obj-C. For one problem, I would use ByteBuffer in Java, but I don't see a suitable class in the Apple documentation. Therefore, I probably should implement this myself.

My question is: how to do this best:

  • Is there a similar class in Obj-C? (That would be a better solution;))
  • Should I do this with Obj-C classes like NSData?
  • Or should I stay with simple C code?
+3
source share
3 answers

You probably want to get NSMutableData.

+8
source

java.nio.ByteBuffer ( Java ) , ByteBuffer / . NSInputStream, NSData ( ):

NSInputStream *inputStream = [NSInputStream inputStreamwithData:myData]; //assuming myData is NSData*

float myFloat;

if([inputStream hasBytesAvailable]) { // NO if you've already read to the end of myData
  NSInteger bytesRead = [inputStream read:&myFloat maxLength:sizeof(myFloat)];
  NSAssert(bytesRead == sizeof(myFloat);
}

- NSOutputStream NSData.

+5

. .

- Obj-C java.nio.ByteBuffer. , ,

.

, NSInputStream NSOutputStream. NSMutableData, .

0

Source: https://habr.com/ru/post/1705271/


All Articles