libc/lzf: Define structures to represent LZF headers.
This commit is contained in:
parent
c8b567db61
commit
ed59157a4b
|
@ -38,8 +38,12 @@
|
||||||
#define LZF_VERSION 0x0105 /* 1.5, API version */
|
#define LZF_VERSION 0x0105 /* 1.5, API version */
|
||||||
#define HLOG CONFIG_LIBC_LZF_HLOG
|
#define HLOG CONFIG_LIBC_LZF_HLOG
|
||||||
|
|
||||||
|
#define LZF_TYPE0_HDR 0
|
||||||
|
#define LZF_TYPE1_HDR 1
|
||||||
|
|
||||||
#define LZF_TYPE0_HDR_SIZE 5
|
#define LZF_TYPE0_HDR_SIZE 5
|
||||||
#define LZF_TYPE1_HDR_SIZE 7
|
#define LZF_TYPE1_HDR_SIZE 7
|
||||||
|
|
||||||
#define LZF_MAX_HDR_SIZE 7
|
#define LZF_MAX_HDR_SIZE 7
|
||||||
#define LZF_MIN_HDR_SIZE 5
|
#define LZF_MIN_HDR_SIZE 5
|
||||||
|
|
||||||
|
@ -47,6 +51,31 @@
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* LZF headers */
|
||||||
|
|
||||||
|
struct lzf_header_s /* Common data header */
|
||||||
|
{
|
||||||
|
uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */
|
||||||
|
uint8_t lzf_type; /* LZF_TYPE0_HDR or LZF_TYPE1_HDR */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lzf_type0_header_s /* Uncompressed data header */
|
||||||
|
{
|
||||||
|
uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */
|
||||||
|
uint8_t lzf_type; /* LZF_TYPE0_HDR */
|
||||||
|
uint8_t lzf_len[2]; /* Data length (big-endian) */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lzf_type1_header_s /* Compressed data header */
|
||||||
|
{
|
||||||
|
uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */
|
||||||
|
uint8_t lzf_type; /* LZF_TYPE1_HDR */
|
||||||
|
uint8_t lzf_clen[2]; /* Compressed data length (big-endian) */
|
||||||
|
uint8_t lzf_ulen[2]; /* Unompressed data length (big-endian) */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* LZF hash table */
|
||||||
|
|
||||||
#if LZF_USE_OFFSETS
|
#if LZF_USE_OFFSETS
|
||||||
# define LZF_HSLOT_BIAS ((const uint8_t *)in_data)
|
# define LZF_HSLOT_BIAS ((const uint8_t *)in_data)
|
||||||
typedef unsigned int lzf_hslot_t;
|
typedef unsigned int lzf_hslot_t;
|
||||||
|
@ -95,7 +124,7 @@ typedef lzf_hslot_t lzf_state_t[1 << HLOG];
|
||||||
size_t lzf_compress(FAR const void *const in_data,
|
size_t lzf_compress(FAR const void *const in_data,
|
||||||
unsigned int in_len, FAR void *out_data,
|
unsigned int in_len, FAR void *out_data,
|
||||||
unsigned int out_len, lzf_state_t htab,
|
unsigned int out_len, lzf_state_t htab,
|
||||||
FAR uint8_t **reshdr);
|
FAR struct lzf_header_s **reshdr);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lzf_decompress
|
* Name: lzf_decompress
|
||||||
|
|
|
@ -126,14 +126,13 @@
|
||||||
size_t lzf_compress(FAR const void *const in_data,
|
size_t lzf_compress(FAR const void *const in_data,
|
||||||
unsigned int in_len, FAR void *out_data,
|
unsigned int in_len, FAR void *out_data,
|
||||||
unsigned int out_len, lzf_state_t htab,
|
unsigned int out_len, lzf_state_t htab,
|
||||||
uint8_t **reshdr)
|
FAR struct lzf_header_s **reshdr)
|
||||||
{
|
{
|
||||||
FAR const uint8_t *ip = (const uint8_t *)in_data;
|
FAR const uint8_t *ip = (const uint8_t *)in_data;
|
||||||
FAR uint8_t *op = (uint8_t *)out_data;
|
FAR uint8_t *op = (uint8_t *)out_data;
|
||||||
FAR const uint8_t *in_end = ip + in_len;
|
FAR const uint8_t *in_end = ip + in_len;
|
||||||
FAR uint8_t *out_end = op + out_len;
|
FAR uint8_t *out_end = op + out_len;
|
||||||
FAR const uint8_t *ref;
|
FAR const uint8_t *ref;
|
||||||
FAR uint8_t *header;
|
|
||||||
ssize_t cs;
|
ssize_t cs;
|
||||||
ssize_t retlen;
|
ssize_t retlen;
|
||||||
|
|
||||||
|
@ -420,30 +419,43 @@ size_t lzf_compress(FAR const void *const in_data,
|
||||||
genhdr:
|
genhdr:
|
||||||
if (cs)
|
if (cs)
|
||||||
{
|
{
|
||||||
header = (uint8_t *)out_data - LZF_TYPE1_HDR_SIZE;
|
FAR struct lzf_type1_header_s *header;
|
||||||
header[0] = 'Z';
|
|
||||||
header[1] = 'V';
|
/* Write compressed */
|
||||||
header[2] = 1;
|
|
||||||
header[3] = cs >> 8;
|
header = (FAR struct lzf_type1_header_s *)
|
||||||
header[4] = cs & 0xff;
|
((uintptr_t)out_data - LZF_TYPE1_HDR_SIZE);
|
||||||
header[5] = in_len >> 8;
|
|
||||||
header[6] = in_len & 0xff;
|
header->lzf_magic[0] = 'Z';
|
||||||
retlen = cs + LZF_TYPE1_HDR_SIZE;
|
header->lzf_magic[1] = 'V';
|
||||||
|
header->lzf_type = LZF_TYPE1_HDR;
|
||||||
|
header->lzf_clen[0] = cs >> 8;
|
||||||
|
header->lzf_clen[1] = cs & 0xff;
|
||||||
|
header->lzf_ulen[0] = in_len >> 8;
|
||||||
|
header->lzf_ulen[1] = in_len & 0xff;
|
||||||
|
|
||||||
|
*reshdr = (FAR struct lzf_header_s *)header;
|
||||||
|
retlen = cs + LZF_TYPE1_HDR_SIZE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
FAR struct lzf_type0_header_s *header;
|
||||||
|
|
||||||
/* Write uncompressed */
|
/* Write uncompressed */
|
||||||
|
|
||||||
header = (uint8_t *)in_data - LZF_TYPE0_HDR_SIZE;
|
header = (FAR struct lzf_type0_header_s *)
|
||||||
header[0] = 'Z';
|
((uintptr_t)in_data - LZF_TYPE0_HDR_SIZE);
|
||||||
header[1] = 'V';
|
|
||||||
header[2] = 0;
|
header->lzf_magic[0] = 'Z';
|
||||||
header[3] = in_len >> 8;
|
header->lzf_magic[1] = 'V';
|
||||||
header[4] = in_len & 0xff;
|
header->lzf_type = LZF_TYPE0_HDR;
|
||||||
retlen = in_len + LZF_TYPE0_HDR_SIZE;
|
header->lzf_len[0] = in_len >> 8;
|
||||||
|
header->lzf_len[1] = in_len & 0xff;
|
||||||
|
|
||||||
|
*reshdr = (FAR struct lzf_header_s *)header;
|
||||||
|
retlen = in_len + LZF_TYPE0_HDR_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
*reshdr = header;
|
|
||||||
return retlen;
|
return retlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue