1################################################################################ 2# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY # 3# Read the zproject/README.md for information about making permanent changes. # 4################################################################################ 5from . import utils 6from . import destructors 7libczmq_destructors = destructors.lib 8 9class Zframe(object): 10 """ 11 working with single message frames 12 """ 13 14 def __init__(self, data, size): 15 """ 16 Create a new frame. If size is not null, allocates the frame data 17 to the specified size. If additionally, data is not null, copies 18 size octets from the specified data into the frame body. 19 """ 20 p = utils.lib.zframe_new(data, size) 21 if p == utils.ffi.NULL: 22 raise MemoryError("Could not allocate person") 23 24 # ffi.gc returns a copy of the cdata object which will have the 25 # destructor called when the Python object is GC'd: 26 # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface 27 self._p = utils.ffi.gc(p, libczmq_destructors.zframe_destroy_py) 28 29 @staticmethod 30 def new_empty(): 31 """ 32 Create an empty (zero-sized) frame 33 """ 34 return utils.lib.zframe_new_empty() 35 36 @staticmethod 37 def from_py(string): 38 """ 39 Create a frame with a specified string content. 40 """ 41 return utils.lib.zframe_from(utils.to_bytes(string)) 42 43 @staticmethod 44 def frommem(data, size, destructor, hint): 45 """ 46 Create a new frame from memory. Take ownership of the memory and calling the destructor 47 on destroy. 48 """ 49 return utils.lib.zframe_frommem(data, size, destructor, hint._p) 50 51 @staticmethod 52 def recv(source): 53 """ 54 Receive frame from socket, returns zframe_t object or NULL if the recv 55 was interrupted. Does a blocking recv, if you want to not block then use 56 zpoller or zloop. 57 """ 58 return utils.lib.zframe_recv(source._p) 59 60 @staticmethod 61 def send(self_p, dest, flags): 62 """ 63 Send a frame to a socket, destroy frame after sending. 64 Return -1 on error, 0 on success. 65 """ 66 return utils.lib.zframe_send(utils.ffi.new("zframe_t **", self_p._p), dest._p, flags) 67 68 def size(self): 69 """ 70 Return number of bytes in frame data 71 """ 72 return utils.lib.zframe_size(self._p) 73 74 def data(self): 75 """ 76 Return address of frame data 77 """ 78 return utils.lib.zframe_data(self._p) 79 80 def meta(self, property): 81 """ 82 Return meta data property for frame 83 The caller shall not modify or free the returned value, which shall be 84 owned by the message. 85 """ 86 return utils.lib.zframe_meta(self._p, utils.to_bytes(property)) 87 88 def dup(self): 89 """ 90 Create a new frame that duplicates an existing frame. If frame is null, 91 or memory was exhausted, returns null. 92 """ 93 return utils.lib.zframe_dup(self._p) 94 95 def strhex(self): 96 """ 97 Return frame data encoded as printable hex string, useful for 0MQ UUIDs. 98 Caller must free string when finished with it. 99 """ 100 return utils.lib.zframe_strhex(self._p) 101 102 def strdup(self): 103 """ 104 Return frame data copied into freshly allocated string 105 Caller must free string when finished with it. 106 """ 107 return utils.lib.zframe_strdup(self._p) 108 109 def streq(self, string): 110 """ 111 Return TRUE if frame body is equal to string, excluding terminator 112 """ 113 return utils.lib.zframe_streq(self._p, utils.to_bytes(string)) 114 115 def more(self): 116 """ 117 Return frame MORE indicator (1 or 0), set when reading frame from socket 118 or by the zframe_set_more() method 119 """ 120 return utils.lib.zframe_more(self._p) 121 122 def set_more(self, more): 123 """ 124 Set frame MORE indicator (1 or 0). Note this is NOT used when sending 125 frame to socket, you have to specify flag explicitly. 126 """ 127 utils.lib.zframe_set_more(self._p, more) 128 129 def routing_id(self): 130 """ 131 Return frame routing ID, if the frame came from a ZMQ_SERVER socket. 132 Else returns zero. 133 """ 134 return utils.lib.zframe_routing_id(self._p) 135 136 def set_routing_id(self, routing_id): 137 """ 138 Set routing ID on frame. This is used if/when the frame is sent to a 139 ZMQ_SERVER socket. 140 """ 141 utils.lib.zframe_set_routing_id(self._p, routing_id) 142 143 def group(self): 144 """ 145 Return frame group of radio-dish pattern. 146 """ 147 return utils.lib.zframe_group(self._p) 148 149 def set_group(self, group): 150 """ 151 Set group on frame. This is used if/when the frame is sent to a 152 ZMQ_RADIO socket. 153 Return -1 on error, 0 on success. 154 """ 155 return utils.lib.zframe_set_group(self._p, utils.to_bytes(group)) 156 157 def eq(self, other): 158 """ 159 Return TRUE if two frames have identical size and data 160 If either frame is NULL, equality is always false. 161 """ 162 return utils.lib.zframe_eq(self._p, other._p) 163 164 def reset(self, data, size): 165 """ 166 Set new contents for frame 167 """ 168 utils.lib.zframe_reset(self._p, data, size) 169 170 def print_py(self, prefix): 171 """ 172 Send message to zsys log sink (may be stdout, or system facility as 173 configured by zsys_set_logstream). Prefix shows before frame, if not null. 174 Long messages are truncated. 175 """ 176 utils.lib.zframe_print(self._p, utils.to_bytes(prefix)) 177 178 def print_n(self, prefix, length): 179 """ 180 Send message to zsys log sink (may be stdout, or system facility as 181 configured by zsys_set_logstream). Prefix shows before frame, if not null. 182 Message length is specified; no truncation unless length is zero. 183 Backwards compatible with zframe_print when length is zero. 184 """ 185 utils.lib.zframe_print_n(self._p, utils.to_bytes(prefix), length) 186 187 @staticmethod 188 def is_py(self): 189 """ 190 Probe the supplied object, and report if it looks like a zframe_t. 191 """ 192 return utils.lib.zframe_is(self._p) 193 194 @staticmethod 195 def test(verbose): 196 """ 197 Self test of this class. 198 """ 199 utils.lib.zframe_test(verbose) 200 201################################################################################ 202# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY # 203# Read the zproject/README.md for information about making permanent changes. # 204################################################################################ 205