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