compress: move compression mode enum to function.h
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
enum b_status b_compressor_create(
|
enum b_status b_compressor_create(
|
||||||
const struct b_compression_function *func, enum b_compressor_mode mode,
|
const struct b_compression_function *func, enum b_compression_mode mode,
|
||||||
struct b_ringbuffer *inbuf, struct b_ringbuffer *outbuf,
|
struct b_ringbuffer *inbuf, struct b_ringbuffer *outbuf,
|
||||||
struct b_compressor **out)
|
struct b_compressor **out)
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,7 @@ enum b_status b_compressor_destroy(struct b_compressor *compressor)
|
|||||||
|
|
||||||
enum b_status b_compressor_compress(struct b_compressor *compressor)
|
enum b_status b_compressor_compress(struct b_compressor *compressor)
|
||||||
{
|
{
|
||||||
if (compressor->c_mode != B_COMPRESSOR_MODE_COMPRESS) {
|
if (compressor->c_mode != B_COMPRESSION_MODE_COMPRESS) {
|
||||||
return B_ERR_BAD_STATE;
|
return B_ERR_BAD_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ enum b_status b_compressor_compress_end(struct b_compressor *compressor)
|
|||||||
|
|
||||||
enum b_status b_compressor_decompress(struct b_compressor *compressor)
|
enum b_status b_compressor_decompress(struct b_compressor *compressor)
|
||||||
{
|
{
|
||||||
if (compressor->c_mode != B_COMPRESSOR_MODE_DECOMPRESS) {
|
if (compressor->c_mode != B_COMPRESSION_MODE_DECOMPRESS) {
|
||||||
return B_ERR_BAD_STATE;
|
return B_ERR_BAD_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#define _COMPRESSOR_H_
|
#define _COMPRESSOR_H_
|
||||||
|
|
||||||
#include <blue/compress/compressor.h>
|
#include <blue/compress/compressor.h>
|
||||||
|
#include <blue/compress/function.h>
|
||||||
|
|
||||||
struct b_compression_function;
|
|
||||||
struct b_ringbuffer;
|
struct b_ringbuffer;
|
||||||
|
|
||||||
enum compressor_flags {
|
enum compressor_flags {
|
||||||
@@ -12,7 +12,7 @@ enum compressor_flags {
|
|||||||
|
|
||||||
struct b_compressor {
|
struct b_compressor {
|
||||||
enum compressor_flags c_flags;
|
enum compressor_flags c_flags;
|
||||||
enum b_compressor_mode c_mode;
|
enum b_compression_mode c_mode;
|
||||||
const struct b_compression_function *c_func;
|
const struct b_compression_function *c_func;
|
||||||
struct b_ringbuffer *c_in, *c_out;
|
struct b_ringbuffer *c_in, *c_out;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const struct b_compression_function *b_compression_function_get_by_id(
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum b_status b_compression_function_get_buffer_size(
|
enum b_status b_compression_function_get_buffer_size(
|
||||||
const struct b_compression_function *func, enum b_compressor_mode mode,
|
const struct b_compression_function *func, enum b_compression_mode mode,
|
||||||
size_t *inbuf_size, size_t *outbuf_size)
|
size_t *inbuf_size, size_t *outbuf_size)
|
||||||
{
|
{
|
||||||
if (!func->f_buffer_size) {
|
if (!func->f_buffer_size) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ struct b_compression_function {
|
|||||||
const char *f_name;
|
const char *f_name;
|
||||||
size_t f_ctx_size;
|
size_t f_ctx_size;
|
||||||
|
|
||||||
enum b_status (*f_buffer_size)(enum b_compressor_mode, size_t *, size_t *);
|
enum b_status (*f_buffer_size)(enum b_compression_mode, size_t *, size_t *);
|
||||||
|
|
||||||
enum b_status (*f_init)(struct b_compressor *);
|
enum b_status (*f_init)(struct b_compressor *);
|
||||||
enum b_status (*f_fini)(struct b_compressor *);
|
enum b_status (*f_fini)(struct b_compressor *);
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ struct zstd_ctx {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static enum b_status buffer_size(
|
static enum b_status buffer_size(
|
||||||
enum b_compressor_mode mode, size_t *inbuf_size, size_t *outbuf_size)
|
enum b_compression_mode mode, size_t *inbuf_size, size_t *outbuf_size)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case B_COMPRESSOR_MODE_COMPRESS:
|
case B_COMPRESSION_MODE_COMPRESS:
|
||||||
*inbuf_size = ZSTD_CStreamInSize();
|
*inbuf_size = ZSTD_CStreamInSize();
|
||||||
*outbuf_size = ZSTD_CStreamOutSize();
|
*outbuf_size = ZSTD_CStreamOutSize();
|
||||||
break;
|
break;
|
||||||
case B_COMPRESSOR_MODE_DECOMPRESS:
|
case B_COMPRESSION_MODE_DECOMPRESS:
|
||||||
*inbuf_size = ZSTD_DStreamInSize();
|
*inbuf_size = ZSTD_DStreamInSize();
|
||||||
*outbuf_size = ZSTD_DStreamOutSize();
|
*outbuf_size = ZSTD_DStreamOutSize();
|
||||||
break;
|
break;
|
||||||
@@ -34,13 +34,13 @@ static enum b_status init(struct b_compressor *compressor)
|
|||||||
{
|
{
|
||||||
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
|
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
|
||||||
switch (compressor->c_mode) {
|
switch (compressor->c_mode) {
|
||||||
case B_COMPRESSOR_MODE_COMPRESS:
|
case B_COMPRESSION_MODE_COMPRESS:
|
||||||
ctx->zstd_c = ZSTD_createCCtx();
|
ctx->zstd_c = ZSTD_createCCtx();
|
||||||
if (!ctx->zstd_c) {
|
if (!ctx->zstd_c) {
|
||||||
return B_ERR_NO_MEMORY;
|
return B_ERR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case B_COMPRESSOR_MODE_DECOMPRESS:
|
case B_COMPRESSION_MODE_DECOMPRESS:
|
||||||
ctx->zstd_d = ZSTD_createDCtx();
|
ctx->zstd_d = ZSTD_createDCtx();
|
||||||
if (!ctx->zstd_d) {
|
if (!ctx->zstd_d) {
|
||||||
return B_ERR_NO_MEMORY;
|
return B_ERR_NO_MEMORY;
|
||||||
@@ -57,10 +57,10 @@ static enum b_status fini(struct b_compressor *compressor)
|
|||||||
{
|
{
|
||||||
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
|
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
|
||||||
switch (compressor->c_mode) {
|
switch (compressor->c_mode) {
|
||||||
case B_COMPRESSOR_MODE_COMPRESS:
|
case B_COMPRESSION_MODE_COMPRESS:
|
||||||
ZSTD_freeCCtx(ctx->zstd_c);
|
ZSTD_freeCCtx(ctx->zstd_c);
|
||||||
break;
|
break;
|
||||||
case B_COMPRESSOR_MODE_DECOMPRESS:
|
case B_COMPRESSION_MODE_DECOMPRESS:
|
||||||
ZSTD_freeDCtx(ctx->zstd_d);
|
ZSTD_freeDCtx(ctx->zstd_d);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -74,10 +74,10 @@ static enum b_status reset(struct b_compressor *compressor)
|
|||||||
{
|
{
|
||||||
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
|
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
|
||||||
switch (compressor->c_mode) {
|
switch (compressor->c_mode) {
|
||||||
case B_COMPRESSOR_MODE_COMPRESS:
|
case B_COMPRESSION_MODE_COMPRESS:
|
||||||
ZSTD_CCtx_reset(ctx->zstd_c, ZSTD_reset_session_only);
|
ZSTD_CCtx_reset(ctx->zstd_c, ZSTD_reset_session_only);
|
||||||
break;
|
break;
|
||||||
case B_COMPRESSOR_MODE_DECOMPRESS:
|
case B_COMPRESSION_MODE_DECOMPRESS:
|
||||||
ZSTD_DCtx_reset(ctx->zstd_d, ZSTD_reset_session_only);
|
ZSTD_DCtx_reset(ctx->zstd_d, ZSTD_reset_session_only);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -8,15 +8,12 @@
|
|||||||
struct b_ringbuffer;
|
struct b_ringbuffer;
|
||||||
struct b_compression_function;
|
struct b_compression_function;
|
||||||
|
|
||||||
|
enum b_compression_mode;
|
||||||
|
|
||||||
typedef struct b_compressor b_compressor;
|
typedef struct b_compressor b_compressor;
|
||||||
|
|
||||||
typedef enum b_compressor_mode {
|
|
||||||
B_COMPRESSOR_MODE_COMPRESS,
|
|
||||||
B_COMPRESSOR_MODE_DECOMPRESS,
|
|
||||||
} b_compressor_mode;
|
|
||||||
|
|
||||||
BLUE_API b_status b_compressor_create(
|
BLUE_API b_status b_compressor_create(
|
||||||
const struct b_compression_function *func, b_compressor_mode mode,
|
const struct b_compression_function *func, enum b_compression_mode mode,
|
||||||
struct b_ringbuffer *inbuf, struct b_ringbuffer *outbuf,
|
struct b_ringbuffer *inbuf, struct b_ringbuffer *outbuf,
|
||||||
b_compressor **out);
|
b_compressor **out);
|
||||||
BLUE_API b_status b_compressor_destroy(b_compressor *compressor);
|
BLUE_API b_status b_compressor_destroy(b_compressor *compressor);
|
||||||
|
|||||||
@@ -13,10 +13,15 @@ typedef enum b_compression_function_id {
|
|||||||
B_COMPRESSOR_FUNCTION_ZSTD,
|
B_COMPRESSOR_FUNCTION_ZSTD,
|
||||||
} b_compression_function_id;
|
} b_compression_function_id;
|
||||||
|
|
||||||
|
typedef enum b_compression_mode {
|
||||||
|
B_COMPRESSION_MODE_COMPRESS,
|
||||||
|
B_COMPRESSION_MODE_DECOMPRESS,
|
||||||
|
} b_compression_mode;
|
||||||
|
|
||||||
BLUE_API const b_compression_function *b_compression_function_get_by_id(
|
BLUE_API const b_compression_function *b_compression_function_get_by_id(
|
||||||
b_compression_function_id id);
|
b_compression_function_id id);
|
||||||
BLUE_API b_status b_compression_function_get_buffer_size(
|
BLUE_API b_status b_compression_function_get_buffer_size(
|
||||||
const b_compression_function *func, enum b_compressor_mode mode,
|
const b_compression_function *func, enum b_compression_mode mode,
|
||||||
size_t *inbuf_size, size_t *outbuf_size);
|
size_t *inbuf_size, size_t *outbuf_size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user