MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / lz4_roundtrip

Function lz4_roundtrip

tests/test_lz4.c:18–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16/* ── Helper: compress + decompress round-trip ──────────────────── */
17
18static int lz4_roundtrip(const char *data, int len) {
19 if (len == 0) {
20 /* Empty input: Go wrapper returns nil without calling LZ4.
21 * LZ4_compress_HC actually returns 1 (end-of-stream marker) for empty input.
22 * Match Go behavior: empty in → empty out is correct. */
23 return 0;
24 }
25
26 int bound = cbm_lz4_bound(len);
27 if (bound <= 0)
28 return -1;
29
30 char *cbuf = malloc(bound);
31 if (!cbuf)
32 return -1;
33
34 int clen = cbm_lz4_compress_hc(data, len, cbuf, bound);
35 if (clen <= 0) {
36 free(cbuf);
37 return -1;
38 }
39
40 char *dbuf = malloc(len);
41 if (!dbuf) {
42 free(cbuf);
43 return -1;
44 }
45
46 int dlen = cbm_lz4_decompress(cbuf, clen, dbuf, len);
47 int ok = (dlen == len && memcmp(dbuf, data, len) == 0) ? 0 : -1;
48
49 free(cbuf);
50 free(dbuf);
51 return ok;
52}
53
54/* ── Tests ─────────────────────────────────────────────────────── */
55

Callers 1

test_lz4.cFile · 0.85

Calls 3

cbm_lz4_boundFunction · 0.85
cbm_lz4_compress_hcFunction · 0.85
cbm_lz4_decompressFunction · 0.85

Tested by

no test coverage detected