36 const char* src_text =
37 "Hello World! This is a test of the zlib compression wrappers in nilorea. "
38 "Repeated data compresses well: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
39 size_t src_len = strlen(src_text) + 1;
42 n_log(
LOG_INFO,
"Source length: %zu, max compressed length: %zu", src_len, max_dst);
44 unsigned char* compressed = NULL;
45 Malloc(compressed,
unsigned char, max_dst);
48 size_t compressed_len =
CompressData((
unsigned char*)src_text, src_len, compressed, max_dst);
49 if (compressed_len == 0) {
54 n_log(
LOG_INFO,
"Compressed %zu bytes to %zu bytes", src_len, compressed_len);
56 unsigned char* decompressed = NULL;
57 Malloc(decompressed,
unsigned char, src_len);
60 size_t decompressed_len =
UncompressData(compressed, compressed_len, decompressed, src_len);
61 if (decompressed_len == 0) {
64 n_log(
LOG_INFO,
"Decompressed %zu bytes back to %zu bytes", compressed_len, decompressed_len);
65 if (strcmp((
char*)decompressed, src_text) == 0) {
68 n_log(
LOG_ERR,
"Raw compress/decompress: data mismatch");
76 "Nilorea Library zlib N_STR test. "
77 "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB "
78 "The quick brown fox jumps over the lazy dog.");
94 if (strcmp(original->
data, unzipped->
data) == 0) {
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_INFO
informational
size_t written
size of the written data inside the string
size_t length
length of string (in case we wanna keep information after the 0 end of string value)
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
A box including a string and his lenght.
size_t GetMaxCompressedLen(size_t nLenSrc)
Return the maximum compressed size.
size_t CompressData(unsigned char *abSrc, size_t nLenSrc, unsigned char *abDst, size_t nLenDst)
Compress a string to another.
size_t UncompressData(unsigned char *abSrc, size_t nLenSrc, unsigned char *abDst, size_t nLenDst)
Uncompress a string to another.
N_STR * unzip_nstr(N_STR *src)
return an uncompressed version of src
N_STR * zip_nstr(N_STR *src)
return a compressed version of src
Common headers and low-level functions & define.
N_STR and string function declaration.
ZLIB compression handler.