MCPcopy Create free account
hub / github.com/assaultcube/AC / putgzbuf

Function putgzbuf

source/src/protocol.cpp:192–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190static uchar *gzbuf = new uchar[GZMSGBUFSIZE]; // not thread-safe, but nesting is no problem
191
192void putgzbuf(vector<uchar> &d, vector<uchar> &s) // zips a vector into a stream, stored in another vector; adds a header to simplify decompression
193{
194 int size = s.length();
195 if(size < 1 || size > MAXGZMSGSIZE) size = 0;
196 uLongf gzbufsize = GZMSGBUFSIZE;
197 if(size && compress2(gzbuf, &gzbufsize, s.getbuf(), size, 9) == Z_OK)
198 {
199 if(gzbufsize > (uint)size)
200 { // use zipped
201 putuint(d, size);
202 putuint(d, (int) gzbufsize);
203 d.put(gzbuf, (int) gzbufsize);
204 return;
205 }
206 }
207 // use raw because it's smaller or because zipping failed
208 putuint(d, size);
209 putuint(d, 0);
210 if(size) d.put(s.getbuf(), size);
211}
212
213ucharbuf *getgzbuf(ucharbuf &p) // fetch a gzipped buffer; needs to be freed properly later
214{

Callers 1

netblockpasteFunction · 0.85

Calls 4

putuintFunction · 0.85
lengthMethod · 0.45
getbufMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected