reader_c.pxd 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import cython
  2. from .mask cimport _websocket_mask_cython as websocket_mask
  3. cdef unsigned int READ_HEADER
  4. cdef unsigned int READ_PAYLOAD_LENGTH
  5. cdef unsigned int READ_PAYLOAD_MASK
  6. cdef unsigned int READ_PAYLOAD
  7. cdef int OP_CODE_NOT_SET
  8. cdef int OP_CODE_CONTINUATION
  9. cdef int OP_CODE_TEXT
  10. cdef int OP_CODE_BINARY
  11. cdef int OP_CODE_CLOSE
  12. cdef int OP_CODE_PING
  13. cdef int OP_CODE_PONG
  14. cdef int COMPRESSED_NOT_SET
  15. cdef int COMPRESSED_FALSE
  16. cdef int COMPRESSED_TRUE
  17. cdef object UNPACK_LEN3
  18. cdef object UNPACK_CLOSE_CODE
  19. cdef object TUPLE_NEW
  20. cdef object WSMsgType
  21. cdef object WSMessage
  22. cdef object WS_MSG_TYPE_TEXT
  23. cdef object WS_MSG_TYPE_BINARY
  24. cdef set ALLOWED_CLOSE_CODES
  25. cdef set MESSAGE_TYPES_WITH_CONTENT
  26. cdef tuple EMPTY_FRAME
  27. cdef tuple EMPTY_FRAME_ERROR
  28. cdef class WebSocketDataQueue:
  29. cdef unsigned int _size
  30. cdef public object _protocol
  31. cdef unsigned int _limit
  32. cdef object _loop
  33. cdef bint _eof
  34. cdef object _waiter
  35. cdef object _exception
  36. cdef public object _buffer
  37. cdef object _get_buffer
  38. cdef object _put_buffer
  39. cdef void _release_waiter(self)
  40. cpdef void feed_data(self, object data, unsigned int size)
  41. @cython.locals(size="unsigned int")
  42. cdef _read_from_buffer(self)
  43. cdef class WebSocketReader:
  44. cdef WebSocketDataQueue queue
  45. cdef unsigned int _max_msg_size
  46. cdef Exception _exc
  47. cdef bytearray _partial
  48. cdef unsigned int _state
  49. cdef int _opcode
  50. cdef bint _frame_fin
  51. cdef int _frame_opcode
  52. cdef list _payload_fragments
  53. cdef Py_ssize_t _frame_payload_len
  54. cdef bytes _tail
  55. cdef bint _has_mask
  56. cdef bytes _frame_mask
  57. cdef Py_ssize_t _payload_bytes_to_read
  58. cdef unsigned int _payload_len_flag
  59. cdef int _compressed
  60. cdef object _decompressobj
  61. cdef bint _compress
  62. cpdef tuple feed_data(self, object data)
  63. @cython.locals(
  64. is_continuation=bint,
  65. fin=bint,
  66. has_partial=bint,
  67. payload_merged=bytes,
  68. )
  69. cpdef void _handle_frame(self, bint fin, int opcode, object payload, int compressed) except *
  70. @cython.locals(
  71. start_pos=Py_ssize_t,
  72. data_len=Py_ssize_t,
  73. length=Py_ssize_t,
  74. chunk_size=Py_ssize_t,
  75. chunk_len=Py_ssize_t,
  76. data_len=Py_ssize_t,
  77. data_cstr="const unsigned char *",
  78. first_byte="unsigned char",
  79. second_byte="unsigned char",
  80. f_start_pos=Py_ssize_t,
  81. f_end_pos=Py_ssize_t,
  82. has_mask=bint,
  83. fin=bint,
  84. had_fragments=Py_ssize_t,
  85. payload_bytearray=bytearray,
  86. )
  87. cpdef void _feed_data(self, bytes data) except *