-# extern void* rmr_init(char* uproto_port, int max_msg_size, int flags)
-rmr_init = rmr_c_lib.rmr_init
-rmr_init.argtypes = [c_char_p, c_int, c_int]
-rmr_init.restype = c_void_p
-
-
-# extern void rmr_close(void* vctx)
-rmr_close = rmr_c_lib.rmr_close
-rmr_close.argtypes = [c_void_p]
-# I don't think there's a restype needed here. THe return is simply "return" in the c lib
-
-# extern int rmr_ready(void* vctx)
-rmr_ready = rmr_c_lib.rmr_ready
-rmr_ready.argtypes = [c_void_p]
-rmr_ready.restype = c_int
-
-# extern int rmr_set_stimeout(void* vctx, int time)
-# RE "int time", from the C docs:
-# Set send timeout. The value time is assumed to be microseconds. The timeout is the
-# rough maximum amount of time that RMr will block on a send attempt when the underlying
-# mechnism indicates eagain or etimeedout. All other error conditions are reported
-# without this delay. Setting a timeout of 0 causes no retries to be attempted in
-# RMr code. Setting a timeout of 1 causes RMr to spin up to 10K retries before returning,
-# but without issuing a sleep. If timeout is > 1, then RMr will issue a sleep (1us)
-# after every 10K send attempts until the time value is reached. Retries are abandoned
-# if NNG returns anything other than NNG_AGAIN or NNG_TIMEDOUT.
-#
-# The default, if this function is not used, is 1; meaning that RMr will retry, but will
-# not enter a sleep. In all cases the caller should check the status in the message returned
-# after a send call.
-rmr_set_stimeout = rmr_c_lib.rmr_set_rtimeout
-rmr_set_stimeout.argtypes = [c_void_p, c_int]
-rmr_set_stimeout.restype = c_int
+_rmr_init = rmr_c_lib.rmr_init
+_rmr_init.argtypes = [c_char_p, c_int, c_int]
+_rmr_init.restype = c_void_p
+
+
+def rmr_init(uproto_port, max_msg_size, flags):
+ """
+ Refer to rmr C documentation for rmr_init
+ extern void* rmr_init(char* uproto_port, int max_msg_size, int flags)
+ """
+ return _rmr_init(uproto_port, max_msg_size, flags)
+
+
+_rmr_ready = rmr_c_lib.rmr_ready
+_rmr_ready.argtypes = [c_void_p]
+_rmr_ready.restype = c_int
+
+
+def rmr_ready(vctx):
+ """
+ Refer to rmr C documentation for rmr_ready
+ extern int rmr_ready(void* vctx)
+ """
+ return _rmr_ready(vctx)
+
+
+_rmr_close = rmr_c_lib.rmr_close
+_rmr_close.argtypes = [c_void_p]
+
+
+def rmr_close(vctx):
+ """
+ Refer to rmr C documentation for rmr_close
+ extern void rmr_close(void* vctx)
+ """
+ return _rmr_close(vctx)
+
+
+_rmr_set_stimeout = rmr_c_lib.rmr_set_stimeout
+_rmr_set_stimeout.argtypes = [c_void_p, c_int]
+_rmr_set_stimeout.restype = c_int
+
+
+def rmr_set_stimeout(vctx, time):
+ """
+ Refer to the rmr C documentation for rmr_set_stimeout
+ extern int rmr_set_stimeout(void* vctx, int time)
+ """
+ return _rmr_set_stimeout(vctx, time)
+
+
+_rmr_alloc_msg = rmr_c_lib.rmr_alloc_msg
+_rmr_alloc_msg.argtypes = [c_void_p, c_int]
+_rmr_alloc_msg.restype = POINTER(rmr_mbuf_t)
+
+
+def rmr_alloc_msg(vctx, size, payload=None, gen_transaction_id=False, mtype=None, meid=None, sub_id=None):
+ """
+ Refer to the rmr C documentation for rmr_alloc_msg
+ extern rmr_mbuf_t* rmr_alloc_msg(void* vctx, int size)
+
+ if payload is not None, attempts to set the payload
+ if gen_transaction_id is True, it generates and sets a transaction id
+ if mtype is not None, sets the sbuf's message type
+ if meid is not None, sets the sbuf's meid
+
+ """
+ sbuf = _rmr_alloc_msg(vctx, size)
+ try:
+ # make sure the alloc worked
+ sbuf.contents
+
+ # set specified fields
+ if payload:
+ set_payload_and_length(payload, sbuf)
+
+ if gen_transaction_id:
+ generate_and_set_transaction_id(sbuf)
+
+ if mtype:
+ sbuf.contents.mtype = mtype
+
+ if meid:
+ rmr_set_meid(sbuf, meid)
+
+ if sub_id:
+ sbuf.contents.sub_id = sub_id
+
+ return sbuf
+
+ except ValueError:
+ raise BadBufferAllocation
+
+
+_rmr_realloc_payload = rmr_c_lib.rmr_realloc_payload
+_rmr_realloc_payload.argtypes = [POINTER(rmr_mbuf_t), c_int, c_int, c_int] # new_len, copy, clone
+_rmr_realloc_payload.restype = POINTER(rmr_mbuf_t)
+
+
+def rmr_realloc_payload(ptr_mbuf, new_len, copy=False, clone=False):
+ """
+ Refer to the rmr C documentation for rmr_realloc_payload().
+ extern rmr_mbuf_t* rmr_realloc_payload(rmr_mbuf_t*, int, int, int)
+ """
+ return _rmr_realloc_payload(ptr_mbuf, new_len, copy, clone)
+
+
+_rmr_free_msg = rmr_c_lib.rmr_free_msg
+_rmr_free_msg.argtypes = [c_void_p]
+_rmr_free_msg.restype = None
+
+
+def rmr_free_msg(mbuf):
+ """
+ Refer to the rmr C documentation for rmr_free_msg
+ extern void rmr_free_msg(rmr_mbuf_t* mbuf )
+ """
+ if mbuf is not None:
+ _rmr_free_msg(mbuf)
+