compress: move compression mode enum to function.h

This commit is contained in:
2025-07-30 18:30:31 +01:00
parent e4c4de94b8
commit 051d371eb5
7 changed files with 25 additions and 23 deletions

View File

@@ -8,7 +8,7 @@
#include <string.h>
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_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)
{
if (compressor->c_mode != B_COMPRESSOR_MODE_COMPRESS) {
if (compressor->c_mode != B_COMPRESSION_MODE_COMPRESS) {
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)
{
if (compressor->c_mode != B_COMPRESSOR_MODE_DECOMPRESS) {
if (compressor->c_mode != B_COMPRESSION_MODE_DECOMPRESS) {
return B_ERR_BAD_STATE;
}

View File

@@ -2,8 +2,8 @@
#define _COMPRESSOR_H_
#include <blue/compress/compressor.h>
#include <blue/compress/function.h>
struct b_compression_function;
struct b_ringbuffer;
enum compressor_flags {
@@ -12,7 +12,7 @@ enum compressor_flags {
struct b_compressor {
enum compressor_flags c_flags;
enum b_compressor_mode c_mode;
enum b_compression_mode c_mode;
const struct b_compression_function *c_func;
struct b_ringbuffer *c_in, *c_out;
};

View File

@@ -26,7 +26,7 @@ const struct b_compression_function *b_compression_function_get_by_id(
}
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)
{
if (!func->f_buffer_size) {

View File

@@ -11,7 +11,7 @@ struct b_compression_function {
const char *f_name;
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_fini)(struct b_compressor *);

View File

@@ -12,14 +12,14 @@ struct zstd_ctx {
};
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) {
case B_COMPRESSOR_MODE_COMPRESS:
case B_COMPRESSION_MODE_COMPRESS:
*inbuf_size = ZSTD_CStreamInSize();
*outbuf_size = ZSTD_CStreamOutSize();
break;
case B_COMPRESSOR_MODE_DECOMPRESS:
case B_COMPRESSION_MODE_DECOMPRESS:
*inbuf_size = ZSTD_DStreamInSize();
*outbuf_size = ZSTD_DStreamOutSize();
break;
@@ -34,13 +34,13 @@ static enum b_status init(struct b_compressor *compressor)
{
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
switch (compressor->c_mode) {
case B_COMPRESSOR_MODE_COMPRESS:
case B_COMPRESSION_MODE_COMPRESS:
ctx->zstd_c = ZSTD_createCCtx();
if (!ctx->zstd_c) {
return B_ERR_NO_MEMORY;
}
break;
case B_COMPRESSOR_MODE_DECOMPRESS:
case B_COMPRESSION_MODE_DECOMPRESS:
ctx->zstd_d = ZSTD_createDCtx();
if (!ctx->zstd_d) {
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);
switch (compressor->c_mode) {
case B_COMPRESSOR_MODE_COMPRESS:
case B_COMPRESSION_MODE_COMPRESS:
ZSTD_freeCCtx(ctx->zstd_c);
break;
case B_COMPRESSOR_MODE_DECOMPRESS:
case B_COMPRESSION_MODE_DECOMPRESS:
ZSTD_freeDCtx(ctx->zstd_d);
break;
default:
@@ -74,10 +74,10 @@ static enum b_status reset(struct b_compressor *compressor)
{
struct zstd_ctx *ctx = b_compressor_get_function_ctx(compressor);
switch (compressor->c_mode) {
case B_COMPRESSOR_MODE_COMPRESS:
case B_COMPRESSION_MODE_COMPRESS:
ZSTD_CCtx_reset(ctx->zstd_c, ZSTD_reset_session_only);
break;
case B_COMPRESSOR_MODE_DECOMPRESS:
case B_COMPRESSION_MODE_DECOMPRESS:
ZSTD_DCtx_reset(ctx->zstd_d, ZSTD_reset_session_only);
break;
default:

View File

@@ -8,15 +8,12 @@
struct b_ringbuffer;
struct b_compression_function;
enum b_compression_mode;
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(
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,
b_compressor **out);
BLUE_API b_status b_compressor_destroy(b_compressor *compressor);

View File

@@ -13,10 +13,15 @@ typedef enum b_compression_function_id {
B_COMPRESSOR_FUNCTION_ZSTD,
} 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(
b_compression_function_id id);
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);
#endif