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