RingBuffer.h 571 B

123456789101112131415161718192021
  1. #import <Foundation/Foundation.h>
  2. @interface RingBuffer : NSObject {
  3. NSMutableData *buffer;
  4. SInt32 position;
  5. SInt32 tail;
  6. }
  7. @property (nonatomic, readonly) UInt32 freeSpace;
  8. //用MutableData初始化
  9. - (instancetype)initWithData:(NSMutableData*)data;
  10. // Returns false if there is not enough free space in buffer
  11. - (BOOL)appendByte:(uint8_t)byte;
  12. // Returns number of bytes written
  13. - (SInt32)appendData:(const NSData*)value offset:(SInt32)offset length:(SInt32)length;
  14. // Returns number of bytes written
  15. - (SInt32)flushToOutputStream:(NSOutputStream*)stream;
  16. @end