2 * Sherlock Library -- Linear Representation of Objects
4 * (c) 2005 Martin Mares <mj@ucw.cz>
5 * (c) 2005 Robert Spalek <robert@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
11 #include "sherlock/sherlock.h"
12 #include "lib/fastbuf.h"
13 #include "lib/unaligned.h"
14 #include "lib/lizard.h"
15 #include "sherlock/object.h"
16 #include "sherlock/lizard-fb.h"
19 obj_linearize(struct odes *d, uns min_compress, uns *plen)
21 // Create uncompressed linearization
22 put_attr_set_type(BUCKET_TYPE_V33);
23 uns size = size_object(d);
24 byte *out = xmalloc(size+LIZARD_COMPRESS_HEADER + LIZARD_NEEDS_CHARS) + LIZARD_COMPRESS_HEADER;
25 byte *t = put_object(out, d);
26 ASSERT(t == out+size);
28 struct lizard_block_req req = {
29 .type = BUCKET_TYPE_V33_LIZARD,
30 .ratio = min_compress / 100.,
36 // Allocate a buffer for compressed data
37 int res = lizard_compress_req(&req);
39 byte *buf = res<0 ? req.out_ptr=xmalloc(req.out_len+=LIZARD_COMPRESS_HEADER) : NULL;
40 res = lizard_compress_req_header(&req, 1);
42 if (req.out_ptr != out-LIZARD_COMPRESS_HEADER)
43 xfree(out-LIZARD_COMPRESS_HEADER);
52 obj_delinearize(struct buck2obj_buf *bbuf, struct mempool *mp, byte *buf, uns len, uns destructive)
54 struct odes *o = obj_new(mp);
55 ASSERT(len >= LIZARD_COMPRESS_HEADER);
56 uns buck_type = buf[0] + BUCKET_TYPE_PLAIN;
59 uns sh = LIZARD_COMPRESS_HEADER - 1;
60 fbbuf_init_read(&fb, buf+sh, len-sh, destructive);
61 if (buck2obj_parse(bbuf, buck_type, len-sh, &fb, NULL, NULL, o, 1) < 0)