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.
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.
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; };
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.
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); };
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.
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 7.3 and later of the OSS® ASN.1 Tools for C++.
Copyright © 2024 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.