message.pxd 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """0MQ Message related class declarations."""
  2. #
  3. # Copyright (c) 2010-2011 Brian E. Granger & Min Ragan-Kelley
  4. #
  5. # This file is part of pyzmq.
  6. #
  7. # pyzmq is free software; you can redistribute it and/or modify it under
  8. # the terms of the Lesser GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # pyzmq is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # Lesser GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the Lesser GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. #-----------------------------------------------------------------------------
  21. # Imports
  22. #-----------------------------------------------------------------------------
  23. from cpython cimport PyBytes_FromStringAndSize
  24. from zmq.backend.cython.libzmq cimport zmq_msg_t, zmq_msg_data, zmq_msg_size
  25. #-----------------------------------------------------------------------------
  26. # Code
  27. #-----------------------------------------------------------------------------
  28. cdef class MessageTracker(object):
  29. cdef set events # Message Event objects to track.
  30. cdef set peers # Other Message or MessageTracker objects.
  31. cdef class Frame:
  32. cdef zmq_msg_t zmq_msg
  33. cdef object _data # The actual message data as a Python object.
  34. cdef object _buffer # A Python Buffer/View of the message contents
  35. cdef object _bytes # A bytes/str copy of the message.
  36. cdef bint _failed_init # Flag to handle failed zmq_msg_init
  37. cdef public object tracker_event # Event for use with zmq_free_fn.
  38. cdef public object tracker # MessageTracker object.
  39. cdef public bint more # whether RCVMORE was set
  40. cdef Frame fast_copy(self) # Create shallow copy of Message object.
  41. cdef object _getbuffer(self) # Construct self._buffer.
  42. cdef inline object copy_zmq_msg_bytes(zmq_msg_t *zmq_msg):
  43. """ Copy the data from a zmq_msg_t """
  44. cdef char *data_c = NULL
  45. cdef Py_ssize_t data_len_c
  46. data_c = <char *>zmq_msg_data(zmq_msg)
  47. data_len_c = zmq_msg_size(zmq_msg)
  48. return PyBytes_FromStringAndSize(data_c, data_len_c)