Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/chunked_ringbuffer: let crb_end_chunk() return size of the chunk #20942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sys/chunked_ringbuffer/chunked_ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
{
const uint8_t *in = data;
for (size_t i = 0; i < len; ++i) {
if (!crb_add_byte(rb ,in[i])) {

Check warning on line 60 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace

Check warning on line 60 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should not be preceded by whitespace
return false;
}
}
Expand All @@ -71,9 +71,9 @@
return false;
}

bool keep = crb_add_bytes(rb ,data, len);

Check warning on line 74 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace

Check warning on line 74 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should not be preceded by whitespace

return crb_end_chunk(rb ,keep);

Check warning on line 76 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace

Check warning on line 76 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should not be preceded by whitespace
}

static unsigned _get_cur_len(chunk_ringbuf_t *rb)
Expand All @@ -87,13 +87,13 @@
}
}

bool crb_end_chunk(chunk_ringbuf_t *rb, bool keep)
unsigned crb_end_chunk(chunk_ringbuf_t *rb, bool keep)
{
int idx;

/* no chunk was started */
if (rb->cur_start == NULL) {
return false;
return 0;
}

if (keep) {
Expand All @@ -109,15 +109,15 @@
}
rb->cur = rb->cur_start;
rb->cur_start = NULL;
return false;
return 0;
}

/* store complete chunk */
rb->chunk_start[idx] = rb->cur_start;
rb->chunk_len[idx] = _get_cur_len(rb);
rb->cur_start = NULL;

return true;
return rb->chunk_len[idx];
}

bool crb_get_chunk_size(chunk_ringbuf_t *rb, size_t *len)
Expand Down Expand Up @@ -228,7 +228,7 @@

void crb_init(chunk_ringbuf_t *rb, void *buffer, size_t len)
{
memset(rb ,0, sizeof(*rb));

Check warning on line 231 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace

Check warning on line 231 in sys/chunked_ringbuffer/chunked_ringbuffer.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should not be preceded by whitespace
rb->buffer = buffer;
rb->buffer_end = &rb->buffer[len - 1];
rb->cur = rb->buffer;
Expand Down
6 changes: 3 additions & 3 deletions sys/include/chunked_ringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ bool crb_add_bytes(chunk_ringbuf_t *rb, const void *data, size_t len);
* @param[in] valid True if the chunk is valid and should be stored
* False if the current chunk should be discarded
*
* @return true If the chunk could be stored in the valid chunk array
* @return false If there is no more space in the valid chunk array
* @return size of chunk if the chunk could be stored in the valid chunk array
* @return 0 if there is no more space in the valid chunk array
*/
bool crb_end_chunk(chunk_ringbuf_t *rb, bool valid);
unsigned crb_end_chunk(chunk_ringbuf_t *rb, bool valid);

/**
* @brief Add a complete chunk to the Ringbuffer
Expand Down
Loading