27 void DpZLibCompressor::cleanupContext(ZLibCtx& ctx) {
28 if (ctx.compression_buffer.getSize() != 0) {
32 if (ctx.zlib_alloc_buffer.getSize() != 0) {
44 if (ctx.compression_buffer.getSize() == 0) {
56 if (ctx.zlib_alloc_buffer.getSize() == 0) {
63 ctx.zlib_stream.zalloc = DpZLibCompressor::zlib_alloc_fn;
64 ctx.zlib_stream.zfree = DpZLibCompressor::zlib_free_fn;
65 ctx.zlib_stream.opaque = &ctx;
67 const CompressionAlgorithm alg = zlibCompressionHelper(ctx, buffer);
76 FW_ASSERT(buffer.
getSize() - write_offset >= ctx.compression_buffer.getSize(),
80 (void)std::memcpy(buffer.
getData() + write_offset, ctx.compression_buffer.getData(),
81 ctx.compression_buffer.getSize());
82 buffer.
setSize(ctx.compression_buffer.getSize() + write_offset);
89 CompressionAlgorithm DpZLibCompressor::zlibCompressionHelper(ZLibCtx& ctx,
const Fw::Buffer& in_buffer) {
95 zlib_ok = deflateInit(&ctx.zlib_stream, compression_level);
96 if (zlib_ok != Z_OK) {
97 ctx.comp.log_WARNING_LO_ZLibInitError(
102 if (in_buffer.
getSize() > std::numeric_limits<uInt>::max() ||
103 ctx.compression_buffer.getSize() > std::numeric_limits<uInt>::max()) {
104 ctx.comp.log_WARNING_LO_BufferTooBigForZLib(in_buffer.
getSize(), ctx.compression_buffer.getSize(),
105 std::numeric_limits<uInt>::max());
109 ctx.zlib_stream.next_in = in_buffer.
getData();
110 ctx.zlib_stream.avail_in =
static_cast<uInt
>(in_buffer.
getSize());
112 ctx.zlib_stream.next_out = ctx.compression_buffer.getData();
113 ctx.zlib_stream.avail_out =
static_cast<uInt
>(ctx.compression_buffer.getSize());
115 zlib_ok = deflate(&ctx.zlib_stream, Z_FINISH);
117 if (zlib_ok == Z_STREAM_END && ctx.zlib_stream.total_out <= ctx.compression_buffer.getSize()) {
118 ctx.compression_buffer.setSize(ctx.zlib_stream.total_out);
120 ctx.comp.log_DIAGNOSTIC_ZLibCompression(in_buffer.
getSize(), ctx.compression_buffer.getSize());
122 ctx.comp.log_DIAGNOSTIC_ZLibMemoryUsage(ctx.bump_allocator, ctx.zlib_alloc_buffer.getSize());
126 if (zlib_ok != Z_OK) {
127 ctx.comp.log_WARNING_LO_ZLibDeflateError(
131 ctx.comp.log_DIAGNOSTIC_ZLibNoCompression(in_buffer.
getSize(), ctx.compression_buffer.getSize());
141 voidpf DpZLibCompressor::zlib_alloc_fn(voidpf opaque, uInt items, uInt size) {
143 ZLibCtx* ctx =
reinterpret_cast<ZLibCtx*
>(opaque);
145 FW_ASSERT(ctx->bump_allocator <= ctx->zlib_alloc_buffer.getSize(),
147 static_cast<FwAssertArgType>(ctx->zlib_alloc_buffer.getSize()));
148 const FwSizeType free_space = ctx->zlib_alloc_buffer.getSize() - ctx->bump_allocator;
152 if (free_space < alloc_size) {
156 U8* alloc_ptr = ctx->zlib_alloc_buffer.getData() + ctx->bump_allocator;
157 ctx->bump_allocator += alloc_size;
162 void DpZLibCompressor::zlib_free_fn(voidpf opaque, voidpf address) {
~DpZLibCompressor()
Destroy DpZLibCompressor object.
DpZLibCompressor(const char *const compName)
Construct DpZLibCompressor object.
#define FW_PARAM_OK(paramValid)
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
Fw::Buffer bufferZLibGet_out(FwIndexType portNum, FwSizeType size) const
Invoke output port bufferZLibGet.
int8_t I8
8-bit signed integer
I8 paramGet_CompressionLevel(Fw::ParamValid &valid)
void bufferCompressionReturn_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port bufferCompressionReturn.
void log_WARNING_LO_ZLibAllocBadBuffer(FwSizeType size)
Auto-generated base for DpZLibCompressor component.
Fw::Buffer bufferCompressionGet_out(FwIndexType portNum, FwSizeType size) const
Invoke output port bufferCompressionGet.
uint8_t U8
8-bit unsigned integer
FwSizeType getSize() const
void bufferZLibReturn_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port bufferZLibReturn.
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
Enum representing parameter validity.
FwSizeType paramGet_ZLibBufferSize(Fw::ParamValid &valid)
void log_WARNING_LO_ZLibCompressionBadBuffer(FwSizeType size)
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.