Utils::ByteBuffer Decompressor::decompress(char* src, unsigned long src_len) { Utils::ByteBuffer dst; unsigned dst_len = 128 * 1024; dst.setSize(dst_len); decompress(dst.getBufferSigned(), dst.getSize(), src, src_len); dst.setSize(decompressed()); return dst; }
uint16_t Packet::serialize(const Message* msg, Utils::ByteBuffer& bfr) { unsigned size = msg->getSerializationSize(); if (size > 65535) throw InvalidMessageSize(size); bfr.setSize(size); return serialize(msg, bfr.getBuffer(), size); }
void Compressor::compress(Utils::ByteBuffer& dst, char* src, unsigned long src_len) { unsigned bfr_size = compressBound(src_len); bool done = false; while (!done) { dst.setSize(bfr_size); try { compress(dst.getBufferSigned(), dst.getSize(), src, src_len); done = true; } catch (BufferTooShort& e) { (void)e; bfr_size <<= 1; } } dst.setSize(m_compressed); }
void Decompressor::decompress(Utils::ByteBuffer& dst, Utils::ByteBuffer& src) { decompress(dst.getBufferSigned(), dst.getSize(), src.getBufferSigned(), src.getSize()); dst.setSize(decompressed()); }