1 /*
2 ################################################################################
3 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
4 # Read the zproject/README.md for information about making permanent changes. #
5 ################################################################################
6 */
7
8 #include "qczmq.h"
9
10 ///
11 // Copy-construct to return the proper wrapped c types
QZchunk(zchunk_t * self,QObject * qObjParent)12 QZchunk::QZchunk (zchunk_t *self, QObject *qObjParent) : QObject (qObjParent)
13 {
14 this->self = self;
15 }
16
17
18 ///
19 // Create a new chunk of the specified size. If you specify the data, it
20 // is copied into the chunk. If you do not specify the data, the chunk is
21 // allocated and left empty, and you can then add data using zchunk_append.
QZchunk(const void * data,size_t size,QObject * qObjParent)22 QZchunk::QZchunk (const void *data, size_t size, QObject *qObjParent) : QObject (qObjParent)
23 {
24 this->self = zchunk_new (data, size);
25 }
26
27 ///
28 // Create a new chunk from memory. Take ownership of the memory and calling the destructor
29 // on destroy.
frommem(void * data,size_t size,zchunk_destructor_fn destructor,void * hint,QObject * qObjParent)30 QZchunk* QZchunk::frommem (void *data, size_t size, zchunk_destructor_fn destructor, void *hint, QObject *qObjParent)
31 {
32 return new QZchunk (zchunk_frommem (data, size, destructor, hint), qObjParent);
33 }
34
35 ///
36 // Destroy a chunk
~QZchunk()37 QZchunk::~QZchunk ()
38 {
39 zchunk_destroy (&self);
40 }
41
42 ///
43 // Resizes chunk max_size as requested; chunk_cur size is set to zero
resize(size_t size)44 void QZchunk::resize (size_t size)
45 {
46 zchunk_resize (self, size);
47
48 }
49
50 ///
51 // Return chunk cur size
size()52 size_t QZchunk::size ()
53 {
54 size_t rv = zchunk_size (self);
55 return rv;
56 }
57
58 ///
59 // Return chunk max size
maxSize()60 size_t QZchunk::maxSize ()
61 {
62 size_t rv = zchunk_max_size (self);
63 return rv;
64 }
65
66 ///
67 // Return chunk data
data()68 byte * QZchunk::data ()
69 {
70 byte * rv = zchunk_data (self);
71 return rv;
72 }
73
74 ///
75 // Set chunk data from user-supplied data; truncate if too large. Data may
76 // be null. Returns actual size of chunk
set(const void * data,size_t size)77 size_t QZchunk::set (const void *data, size_t size)
78 {
79 size_t rv = zchunk_set (self, data, size);
80 return rv;
81 }
82
83 ///
84 // Fill chunk data from user-supplied octet
fill(byte filler,size_t size)85 size_t QZchunk::fill (byte filler, size_t size)
86 {
87 size_t rv = zchunk_fill (self, filler, size);
88 return rv;
89 }
90
91 ///
92 // Append user-supplied data to chunk, return resulting chunk size. If the
93 // data would exceeded the available space, it is truncated. If you want to
94 // grow the chunk to accommodate new data, use the zchunk_extend method.
append(const void * data,size_t size)95 size_t QZchunk::append (const void *data, size_t size)
96 {
97 size_t rv = zchunk_append (self, data, size);
98 return rv;
99 }
100
101 ///
102 // Append user-supplied data to chunk, return resulting chunk size. If the
103 // data would exceeded the available space, the chunk grows in size.
extend(const void * data,size_t size)104 size_t QZchunk::extend (const void *data, size_t size)
105 {
106 size_t rv = zchunk_extend (self, data, size);
107 return rv;
108 }
109
110 ///
111 // Copy as much data from 'source' into the chunk as possible; returns the
112 // new size of chunk. If all data from 'source' is used, returns exhausted
113 // on the source chunk. Source can be consumed as many times as needed until
114 // it is exhausted. If source was already exhausted, does not change chunk.
consume(QZchunk * source)115 size_t QZchunk::consume (QZchunk *source)
116 {
117 size_t rv = zchunk_consume (self, source->self);
118 return rv;
119 }
120
121 ///
122 // Returns true if the chunk was exhausted by consume methods, or if the
123 // chunk has a size of zero.
exhausted()124 bool QZchunk::exhausted ()
125 {
126 bool rv = zchunk_exhausted (self);
127 return rv;
128 }
129
130 ///
131 // Read chunk from an open file descriptor
read(FILE * handle,size_t bytes)132 QZchunk * QZchunk::read (FILE *handle, size_t bytes)
133 {
134 QZchunk *rv = new QZchunk (zchunk_read (handle, bytes));
135 return rv;
136 }
137
138 ///
139 // Write chunk to an open file descriptor
write(FILE * handle)140 int QZchunk::write (FILE *handle)
141 {
142 int rv = zchunk_write (self, handle);
143 return rv;
144 }
145
146 ///
147 // Try to slurp an entire file into a chunk. Will read up to maxsize of
148 // the file. If maxsize is 0, will attempt to read the entire file and
149 // fail with an assertion if that cannot fit into memory. Returns a new
150 // chunk containing the file data, or NULL if the file could not be read.
slurp(const QString & filename,size_t maxsize)151 QZchunk * QZchunk::slurp (const QString &filename, size_t maxsize)
152 {
153 QZchunk *rv = new QZchunk (zchunk_slurp (filename.toUtf8().data(), maxsize));
154 return rv;
155 }
156
157 ///
158 // Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
159 // object, or null if there was not enough heap memory. If chunk is null,
160 // returns null.
dup()161 QZchunk * QZchunk::dup ()
162 {
163 QZchunk *rv = new QZchunk (zchunk_dup (self));
164 return rv;
165 }
166
167 ///
168 // Return chunk data encoded as printable hex string. Caller must free
169 // string when finished with it.
strhex()170 QString QZchunk::strhex ()
171 {
172 char *retStr_ = zchunk_strhex (self);
173 QString rv = QString (retStr_);
174 zstr_free (&retStr_);
175 return rv;
176 }
177
178 ///
179 // Return chunk data copied into freshly allocated string
180 // Caller must free string when finished with it.
strdup()181 QString QZchunk::strdup ()
182 {
183 char *retStr_ = zchunk_strdup (self);
184 QString rv = QString (retStr_);
185 zstr_free (&retStr_);
186 return rv;
187 }
188
189 ///
190 // Return TRUE if chunk body is equal to string, excluding terminator
streqNoConflict(const QString & string)191 bool QZchunk::streqNoConflict (const QString &string)
192 {
193 bool rv = zchunk_streq (self, string.toUtf8().data());
194 return rv;
195 }
196
197 ///
198 // Transform zchunk into a zframe that can be sent in a message.
pack()199 QZframe * QZchunk::pack ()
200 {
201 QZframe *rv = new QZframe (zchunk_pack (self));
202 return rv;
203 }
204
205 ///
206 // Transform zchunk into a zframe that can be sent in a message.
207 // Take ownership of the chunk.
packx()208 QZframe * QZchunk::packx ()
209 {
210 QZframe *rv = new QZframe (zchunk_packx (&self));
211 return rv;
212 }
213
214 ///
215 // Transform a zframe into a zchunk.
unpack(QZframe * frame)216 QZchunk * QZchunk::unpack (QZframe *frame)
217 {
218 QZchunk *rv = new QZchunk (zchunk_unpack (frame->self));
219 return rv;
220 }
221
222 ///
223 // Calculate SHA1 digest for chunk, using zdigest class.
digest()224 const QString QZchunk::digest ()
225 {
226 const QString rv = QString (zchunk_digest (self));
227 return rv;
228 }
229
230 ///
231 // Dump chunk to FILE stream, for debugging and tracing.
fprint(FILE * file)232 void QZchunk::fprint (FILE *file)
233 {
234 zchunk_fprint (self, file);
235
236 }
237
238 ///
239 // Dump message to stderr, for debugging and tracing.
240 // See zchunk_fprint for details
print()241 void QZchunk::print ()
242 {
243 zchunk_print (self);
244
245 }
246
247 ///
248 // Probe the supplied object, and report if it looks like a zchunk_t.
is(void * self)249 bool QZchunk::is (void *self)
250 {
251 bool rv = zchunk_is (self);
252 return rv;
253 }
254
255 ///
256 // Self test of this class.
test(bool verbose)257 void QZchunk::test (bool verbose)
258 {
259 zchunk_test (verbose);
260
261 }
262 /*
263 ################################################################################
264 # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
265 # Read the zproject/README.md for information about making permanent changes. #
266 ################################################################################
267 */
268