TOP

Compressor Classes

Applies to: ASN.1/C++ 6.5

This functionality is available to the OSS Space-Optimized and Lean Encoders/Decoders. It can compact ASN.1 encodings seamlessly for you, which is especially useful for verbose text encodings such as XER and E-XER.

To use this feature create the instance of compression class and pass it as the argument to the OssControl class setCompressor method.

The OSS ASN.1 API provides the OssCompressor abstract class as a base compression class and the OssZlibCompressor class that implements zlib compression. You can use the OssZlibCompressor class or write your own customized compression class inherited from OssCompressor to implement your compression/encryption/transformation functions. See Sample Compression Programs for examples that use both methods.

The encoder will automatically compress encoded data for you to transmit or store efficiently. Similarly, the decoder will automatically uncompress and decode the data for you.

For your convenience, the compression algorithm used in the OssZlibCompressor class is the standard zlib found at http://www.gzip.org/zlib.

OssCompressor

This is an abstract class which provides three virtual methods. This class can be used as a base class to create any customized new class to support user-defined compression or encryption algorithms.

Definition

class PUBLIC OssCompressor {
public:
    virtual int compress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen) = 0;
    virtual int decompress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen) = 0;
    virtual size_t compress_estimate(void *inbuf, size_t inlen) = 0;
};

Methods

virtual int compress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen)
This is a base compression method. This method is called by the encoder to compress the encoded data. On success it returns a zero, otherwise a non-zero error code is returned. Following are descriptions of the parameters.

void *inbuf - input buffer which contains the input encoded data to be compressed.

size_t inlen - length of the input data

void *outbuf - output buffer that holds the compressed data which is updated by the compress method and returned to the encoder.

size_t outlen - length of the output buffer, which is updated by the compress method and returned to the encoder.
virtual int decompress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen)
This is a base decompression method. This method is called by the decoder to decompress the encoded data before it starts decoding. On success it returns a zero, otherwise a non-zero error code is returned. Following are the description of the parameters.

void *inbuf - input buffer, which contains the input encoded data to be decompressed.

size_t inlen - length of the input encoded data.

void *outbuf - output buffer that holds the decompressed data which is updated by the decompress method and returned to the decoder.

size_t outlen - length of the output buffer, which is updated by the compress method and returned to the decoder.
virtual size_t compress_estimate(void *inbuf, size_t inlen)
This is a base method used to calculate the estimated maximum compressed data size and then return the value to the caller. Following is the description of the parameters.

void *inbuf - input buffer, which contains the input encoded data to be decompressed.

size_t inlen - length of the input buffer.

OssZlibCompressor

This class is supported by OSS to provide the default zlib compress and decompress methods. It supports two levels of compression, Z_DEFAULT_COMPRESSION and Z_BEST_COMPRESSION. By default it uses Z_DEFAULT_COMPRESSION compression.

Definition

class PUBLIC OssZlibCompressor : public OssCompressor {
public:
    OssZlibCompressor();
    OssZlibCompressor(int lvl);
    int compress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen);
    int decompress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen);
    size_t compress_estimate(void *inbuf, size_t inlen);
    int get_compressionLevel();
    void set_compressionLevel(int level);
};

Methods

OssZlibCompressor();
This is the default constructor, which sets the compression level to zlib default compression.
OssZlibCompressor(int lvl);
This is another constructor which takes the compression level as a parameter and sets the value.

NOTE: There is no need to call the compress and decompress methods of the OssZlibCompressor class explicitly. It is enough to create an instance of this class and set it via the setCompressor method of the OssControl class. Then the compress/decompress functions will be called automatically by the encoder and decoder.

int compress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen);
This method compresses the encoded data, as mentioned in the OssCompressor class section above, and returns the status of the compression.
int decompress(void *inbuf, size_t inlen, void *outbuf, size_t *outlen);
This method decompresses the encoded data, as mentioned in the OssCompressor class section above, and returns the status.
size_t compress_estimate(void *inbuf, size_t inlen);
As mentioned above, this method is used for estimating the size of the compressed and decompressed data.
int get_compressionLevel();
Returns the currently set compression level.
void set_compressionLevel(int level);
Set the compression level as provided in the parameter.

See Sample Compression Programs for examples that use the OssZlibCompressor class and custom compression.

NOTE: As of version 4.3.1, a separate zlib library is not provided in the OSS ASN.1/C++ Tools shipment.

Typically, the names of zlib library files are:

Windows platforms: zlib.lib (zlibstat.lib), the static version, and zdll.lib (zlib1.lib), the DLL import library, which loads zlib1.dll.

Non-Windows platforms: libz.a, the static version, and libz.so, the shared version.

You can link your application with a system copy of the zlib library on your system; in this case we recommend that you link with the dynamic version (libz.so on UNIX and zdll.lib (zlib1.lib) on Windows) in order to get all the updates and security patches immediately when a system copy of zlib is renewed. The drawback is that the zlib dynamic library should be available at runtime (LD_LIBRARY_PATH on UNIX and the environment variable, PATH, on Win32 should point to the library (zlib1.dll)).


This documentation applies to release 6.5 and later of the OSS® ASN.1 Tools for C++.

Copyright © 2017 OSS Nokalva, Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise, without the prior permission of OSS Nokalva, Inc.
Every distributed copy of the OSS® ASN.1 Tools for C++ is associated with a specific license and related unique license number. That license determines, among other things, what functions of the OSS ASN.1 Tools for C++ are available to you.