50{
51 z_stream c_stream;
52
53 c_stream.zalloc = (alloc_func)0;
54 c_stream.zfree = (free_func)0;
55 c_stream.opaque = (voidpf)0;
56
57
59 if (z_res != Z_OK)
60 {
61 LOG_ERROR(
"entities.object",
"Can't compress update packet (zlib: deflateInit) Error code: {} ({})", z_res, zError(z_res));
62 *dst_size = 0;
63 return;
64 }
65
66 c_stream.next_out = (Bytef*)dst;
67 c_stream.avail_out = *dst_size;
68 c_stream.next_in = (Bytef*)src;
69 c_stream.avail_in = (uInt)src_size;
70
71 z_res = deflate(&c_stream, Z_NO_FLUSH);
72 if (z_res != Z_OK)
73 {
74 LOG_ERROR(
"entities.object",
"Can't compress update packet (zlib: deflate) Error code: {} ({})", z_res, zError(z_res));
75 *dst_size = 0;
76 return;
77 }
78
79 if (c_stream.avail_in != 0)
80 {
81 LOG_ERROR(
"entities.object",
"Can't compress update packet (zlib: deflate not greedy)");
82 *dst_size = 0;
83 return;
84 }
85
86 z_res = deflate(&c_stream, Z_FINISH);
87 if (z_res != Z_STREAM_END)
88 {
89 LOG_ERROR(
"entities.object",
"Can't compress update packet (zlib: deflate should report Z_STREAM_END instead {} ({})", z_res, zError(z_res));
90 *dst_size = 0;
91 return;
92 }
93
94 z_res = deflateEnd(&c_stream);
95 if (z_res != Z_OK)
96 {
97 LOG_ERROR(
"entities.object",
"Can't compress update packet (zlib: deflateEnd) Error code: {} ({})", z_res, zError(z_res));
98 *dst_size = 0;
99 return;
100 }
101
102 *dst_size = c_stream.total_out;
103}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
@ CONFIG_COMPRESSION
Definition: IWorld.h:208
#define sWorld
Definition: World.h:451