68 if (src->
written > (
size_t)INT_MAX) {
73 int src_len = (int)src->
written;
74 int max_compressed = LZ4_compressBound(src_len);
75 if (max_compressed <= 0) {
85 uint32_t src_length_be = htonl((uint32_t)src->
written);
86 memcpy(zipped->
data, &src_length_be,
sizeof(uint32_t));
87 char* dataptr = zipped->
data + 4;
89 int compressed = LZ4_compress_default(src->
data, dataptr, src_len, max_compressed);
90 if (compressed <= 0) {
91 n_log(
LOG_ERR,
"LZ4_compress_default failed (src=%d bytes)", src_len);
95 zipped->
written = (size_t)(4 + compressed);
116 uint32_t original_size = 0;
117 memcpy(&original_size, src->
data,
sizeof(uint32_t));
118 original_size = ntohl(original_size);
119 if (original_size == 0) {
120 n_log(
LOG_ERR,
"lz4 frame declares original_size == 0");
123 if (original_size > 256u * 1024u * 1024u) {
124 n_log(
LOG_ERR,
"lz4 frame declares absurd original_size %u", original_size);
132 size_t compressed_bytes = src->
written - 4;
133 if (compressed_bytes > (
size_t)INT_MAX) {
139 int decoded = LZ4_decompress_safe(src->
data + 4, unzipped->
data,
140 (
int)compressed_bytes, (
int)original_size);
142 n_log(
LOG_ERR,
"LZ4_decompress_safe failed (compressed=%zu, original=%u)",
143 compressed_bytes, original_size);
147 unzipped->
written = (size_t)decoded;
#define __n_assert(__ptr, __ret)
macro to assert things
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
N_STR * zip4_nstr(N_STR *src)
Compress src with LZ4 block format.
N_STR * unzip4_nstr(N_STR *src)
Decompress an N_STR produced by zip4_nstr.
size_t written
number of meaningful bytes in data, excluding the null terminator; the size including the null termin...
size_t length
total allocation (in bytes) of the data buffer, padding included
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
A box including a string and his lenght.
Common headers and low-level functions & define.
LZ4 block-compression handler.
N_STR and string function declaration.