SRIOConsumer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Copyright 2012 Square Inc.
  3. // Portions Copyright (c) 2016-present, Facebook, Inc.
  4. //
  5. // All rights reserved.
  6. //
  7. // This source code is licensed under the BSD-style license found in the
  8. // LICENSE file in the root directory of this source tree. An additional grant
  9. // of patent rights can be found in the PATENTS file in the same directory.
  10. //
  11. #import <Foundation/Foundation.h>
  12. @class SRWebSocket; // TODO: (nlutsenko) Remove dependency on SRWebSocket here.
  13. // Returns number of bytes consumed. Returning 0 means you didn't match.
  14. // Sends bytes to callback handler;
  15. typedef size_t (^stream_scanner)(NSData *collected_data);
  16. typedef void (^data_callback)(SRWebSocket *webSocket, NSData *data);
  17. @interface SRIOConsumer : NSObject {
  18. stream_scanner _scanner;
  19. data_callback _handler;
  20. size_t _bytesNeeded;
  21. BOOL _readToCurrentFrame;
  22. BOOL _unmaskBytes;
  23. }
  24. @property (nonatomic, copy, readonly) stream_scanner consumer;
  25. @property (nonatomic, copy, readonly) data_callback handler;
  26. @property (nonatomic, assign) size_t bytesNeeded;
  27. @property (nonatomic, assign, readonly) BOOL readToCurrentFrame;
  28. @property (nonatomic, assign, readonly) BOOL unmaskBytes;
  29. - (void)resetWithScanner:(stream_scanner)scanner
  30. handler:(data_callback)handler
  31. bytesNeeded:(size_t)bytesNeeded
  32. readToCurrentFrame:(BOOL)readToCurrentFrame
  33. unmaskBytes:(BOOL)unmaskBytes;
  34. @end