Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesnicholson committed Dec 30, 2023
1 parent 6aaa6be commit 7843d09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
28 changes: 14 additions & 14 deletions cobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ cobs_ret_t cobs_decode(void const *enc,
size_t src_len;
bool decode_complete;
if ((r = cobs_decode_inc(&ctx,
&(cobs_decode_inc_args_t){ .src = enc,
.dst = out_dec,
.src_max = enc_len,
.dst_max = dec_max },
&(cobs_decode_inc_args_t){ .enc_src = enc,
.dec_dst = out_dec,
.enc_src_max = enc_len,
.dec_dst_max = dec_max },
&src_len,
out_dec_len,
&decode_complete)) != COBS_RET_SUCCESS) {
Expand All @@ -214,21 +214,21 @@ cobs_ret_t cobs_decode_inc_begin(cobs_decode_inc_ctx_t *ctx) {

cobs_ret_t cobs_decode_inc(cobs_decode_inc_ctx_t *ctx,
cobs_decode_inc_args_t const *args,
size_t *out_src_len,
size_t *out_dst_len,
size_t *out_enc_src_len,
size_t *out_dec_dst_len,
bool *out_decode_complete) {
if (!ctx || !args || !out_src_len || !out_dst_len || !out_decode_complete ||
!args->dst || !args->src) {
if (!ctx || !args || !out_enc_src_len || !out_dec_dst_len || !out_decode_complete ||
!args->dec_dst || !args->enc_src) {
return COBS_RET_ERR_BAD_ARG;
}

bool decode_complete = false;
size_t src_idx = 0, dst_idx = 0;

size_t const src_max = args->src_max;
size_t const dst_max = args->dst_max;
cobs_byte_t const *src_b = (cobs_byte_t const *)args->src;
cobs_byte_t *dst_b = (cobs_byte_t *)args->dst;
size_t const src_max = args->enc_src_max;
size_t const dst_max = args->dec_dst_max;
cobs_byte_t const *src_b = (cobs_byte_t const *)args->enc_src;
cobs_byte_t *dst_b = (cobs_byte_t *)args->dec_dst;
unsigned block = ctx->block, code = ctx->code;
enum cobs_decode_inc_state state = ctx->state;

Expand Down Expand Up @@ -277,8 +277,8 @@ cobs_ret_t cobs_decode_inc(cobs_decode_inc_ctx_t *ctx,
ctx->state = state;
ctx->code = (uint8_t)code;
ctx->block = (uint8_t)block;
*out_dst_len = dst_idx;
*out_src_len = src_idx;
*out_dec_dst_len = dst_idx;
*out_enc_src_len = src_idx;
*out_decode_complete = decode_complete;
return COBS_RET_SUCCESS;
}
12 changes: 6 additions & 6 deletions cobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ typedef struct cobs_decode_inc_ctx {
} cobs_decode_inc_ctx_t;

typedef struct cobs_decode_inc_args {
void const *src; // pointer to current position of encoded payload
void *dst; // pointer to decoded buffer.
size_t src_max; // length of the |src| input buffer.
size_t dst_max; // length of the |dst| output buffer.
void const *enc_src; // pointer to current position of encoded payload
void *dec_dst; // pointer to decoded buffer.
size_t enc_src_max; // length of the |src| input buffer.
size_t dec_dst_max; // length of the |dst| output buffer.
} cobs_decode_inc_args_t;

cobs_ret_t cobs_decode_inc_begin(cobs_decode_inc_ctx_t *ctx);
cobs_ret_t cobs_decode_inc(cobs_decode_inc_ctx_t *ctx,
cobs_decode_inc_args_t const *args,
size_t *out_src_len, // how many bytes of src were read
size_t *out_dst_len, // how many bytes written to dst
size_t *out_enc_src_len, // how many bytes of src were read
size_t *out_dec_dst_len, // how many bytes written to dst
bool *out_decode_complete);

#ifdef __cplusplus
Expand Down
20 changes: 10 additions & 10 deletions tests/test_cobs_decode_inc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ TEST_CASE("cobs_decode_inc") {
REQUIRE(cobs_decode_inc_begin(&ctx) == COBS_RET_SUCCESS);

byte_vec_t enc(1024), dec(enc.size() * 2);
cobs_decode_inc_args_t args{ .src = enc.data(),
.dst = dec.data(),
.src_max = enc.size(),
.dst_max = dec.size() };
cobs_decode_inc_args_t args{ .enc_src = enc.data(),
.dec_dst = dec.data(),
.enc_src_max = enc.size(),
.dec_dst_max = dec.size() };
size_t enc_len{ 0u }, dec_len{ 0u };
bool done{ false };

Expand All @@ -40,12 +40,12 @@ TEST_CASE("cobs_decode_inc") {
COBS_RET_ERR_BAD_ARG);

SUBCASE("args.src") {
args.src = nullptr;
args.enc_src = nullptr;
REQUIRE(cobs_decode_inc(&ctx, &args, &enc_len, &dec_len, &done) ==
COBS_RET_ERR_BAD_ARG);
}
SUBCASE("args.dst") {
args.dst = nullptr;
args.dec_dst = nullptr;
REQUIRE(cobs_decode_inc(&ctx, &args, &enc_len, &dec_len, &done) ==
COBS_RET_ERR_BAD_ARG);
}
Expand Down Expand Up @@ -73,10 +73,10 @@ TEST_CASE("cobs_decode_inc") {

size_t cur_dec{ 0 }, cur_enc{ 0 };
while (!done) {
args.src = &enc[cur_enc];
args.dst = &dec[cur_dec];
args.src_max = 1;
args.dst_max = 1;
args.enc_src = &enc[cur_enc];
args.dec_dst = &dec[cur_dec];
args.enc_src_max = 1;
args.dec_dst_max = 1;

size_t this_enc_len{ 0u }, this_dec_len{ 0u };
REQUIRE_MESSAGE(cobs_decode_inc(&ctx, &args, &this_enc_len, &this_dec_len, &done) ==
Expand Down

0 comments on commit 7843d09

Please sign in to comment.