# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


from pyczmq._cffi import C, cdef, ffi, ptop

@cdef('zframe_t * zframe_recv_nowait (void *socket);', nullable=True)
def recv_nowait(sock):
    """
    Receive a new frame off the socket. Returns newly allocated frame, or
    NULL if there was no input waiting, or if the read was interrupted.
    """
    return C.zframe_recv_nowait(sock)


@cdef('int zframe_send (zframe_t **self_p, void *socket, int flags);')
def send(frame, socket, flags):
    """
    Send a frame to a socket, destroy frame after sending.
    Return -1 on error, 0 on success.
    """
    return C.zframe_send(ptop('zframe_t', frame), socket, flags)


@cdef('size_t zframe_size (zframe_t *self);')
def size(frame):
    """Return number of bytes in frame data
    """
    return C.zframe_size(frame)


@cdef('void * zframe_data (zframe_t *self);')
def data(frame):
    """Return frame data
    """

# Path: pyczmq/_cffi.py
# C = ffi.dlopen('czmq')
# Z = ffi.dlopen('zmq')
# def ptop(typ, val):
# def cdef(decl, returns_string=False, nullable=False):
#     def wrap(f):
#         def inner_f(*args):


# Path: pyczmq/zframe.py
from pyczmq._cffi import C, cdef, ffi, ptop


@cdef('zframe_t * zframe_recv_nowait (void *socket);', nullable=True)
def recv_nowait(sock):
    """
    Receive a new frame off the socket. Returns newly allocated frame, or
    NULL if there was no input waiting, or if the read was interrupted.
    """
    return C.zframe_recv_nowait(sock)


@cdef('int zframe_send (zframe_t **self_p, void *socket, int flags);')
def send(frame, socket, flags):
    """
    Send a frame to a socket, destroy frame after sending.
    Return -1 on error, 0 on success.
    """
    return C.zframe_send(ptop('zframe_t', frame), socket, flags)


@cdef('size_t zframe_size (zframe_t *self);')
def size(frame):
    """Return number of bytes in frame data
    """
    return C.zframe_size(frame)


@cdef('void * zframe_data (zframe_t *self);')
def data(frame):
    """Return frame data
    """

    return ffi.buffer(C.zframe_data(frame), C.zframe_size(frame))