25 void DpZLibCompressor::cleanupContext(ZLibCtx& ctx) {
26 if (ctx.compression_buffer.getSize() != 0) {
30 if (ctx.zlib_alloc_buffer.getSize() != 0) {
42 if (ctx.compression_buffer.getSize() == 0) {
54 if (ctx.zlib_alloc_buffer.getSize() == 0) {
61 ctx.zlib_stream.zalloc = DpZLibCompressor::zlib_alloc_fn;
62 ctx.zlib_stream.zfree = DpZLibCompressor::zlib_free_fn;
63 ctx.zlib_stream.opaque = &ctx;
65 const CompressionAlgorithm alg = zlibCompressionHelper(ctx, buffer);
74 FW_ASSERT(buffer.
getSize() - write_offset >= ctx.compression_buffer.getSize(),
78 (void)std::memcpy(buffer.
getData() + write_offset, ctx.compression_buffer.getData(),
79 ctx.compression_buffer.getSize());
80 buffer.
setSize(ctx.compression_buffer.getSize() + write_offset);
87 CompressionAlgorithm DpZLibCompressor::zlibCompressionHelper(ZLibCtx& ctx,
const Fw::Buffer& in_buffer) {
93 zlib_ok = deflateInit(&ctx.zlib_stream, compression_level);
94 if (zlib_ok != Z_OK) {
95 ctx.comp.log_WARNING_LO_ZLibInitError(
100 if (in_buffer.
getSize() > std::numeric_limits<uInt>::max() ||
101 ctx.compression_buffer.getSize() > std::numeric_limits<uInt>::max()) {
102 ctx.comp.log_WARNING_LO_BufferTooBigForZLib(in_buffer.
getSize(), ctx.compression_buffer.getSize(),
103 std::numeric_limits<uInt>::max());
107 ctx.zlib_stream.next_in = in_buffer.
getData();
108 ctx.zlib_stream.avail_in =
static_cast<uInt
>(in_buffer.
getSize());
110 ctx.zlib_stream.next_out = ctx.compression_buffer.getData();
111 ctx.zlib_stream.avail_out =
static_cast<uInt
>(ctx.compression_buffer.getSize());
113 zlib_ok = deflate(&ctx.zlib_stream, Z_FINISH);
115 if (zlib_ok == Z_STREAM_END && ctx.zlib_stream.total_out <= ctx.compression_buffer.getSize()) {
116 ctx.compression_buffer.setSize(ctx.zlib_stream.total_out);
118 ctx.comp.log_DIAGNOSTIC_ZLibCompression(in_buffer.
getSize(), ctx.compression_buffer.getSize());
120 ctx.comp.log_DIAGNOSTIC_ZLibMemoryUsage(ctx.bump_allocator, ctx.zlib_alloc_buffer.getSize());
124 if (zlib_ok != Z_OK) {
125 ctx.comp.log_WARNING_LO_ZLibDeflateError(
129 ctx.comp.log_DIAGNOSTIC_ZLibNoCompression(in_buffer.
getSize(), ctx.compression_buffer.getSize());
139 voidpf DpZLibCompressor::zlib_alloc_fn(voidpf opaque, uInt items, uInt size) {
141 ZLibCtx* ctx =
reinterpret_cast<ZLibCtx*
>(opaque);
143 FW_ASSERT(ctx->bump_allocator <= ctx->zlib_alloc_buffer.getSize(),
145 static_cast<FwAssertArgType>(ctx->zlib_alloc_buffer.getSize()));
146 const FwSizeType free_space = ctx->zlib_alloc_buffer.getSize() - ctx->bump_allocator;
150 if (free_space < alloc_size) {
154 U8* alloc_ptr = ctx->zlib_alloc_buffer.getData() + ctx->bump_allocator;
155 ctx->bump_allocator += alloc_size;
160 void DpZLibCompressor::zlib_free_fn(voidpf opaque, voidpf address) {
~DpZLibCompressor()
Destroy DpZLibCompressor object.
DpZLibCompressor(const char *const compName)
Construct DpZLibCompressor object.
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.