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

chore: eliminate [in/out] parameters #94

Merged
merged 24 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ target_compile_options(
-Wextra
-Wpedantic
-Werror
-Og
-ggdb
)
target_include_directories(
note_c
Expand Down
14 changes: 10 additions & 4 deletions n_cobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <stdint.h>

#define COBS_EOP_OVERHEAD 1

//**************************************************************************/
/*!
@brief Decode a string encoded with COBS encoding
Expand Down Expand Up @@ -94,6 +96,7 @@ uint32_t cobsEncode(uint8_t *ptr, uint32_t length, uint8_t eop, uint8_t *dst)
@param length Length of the data to encode

@return the length required for encoded data

@note The computed length does not include the EOP (end-of-packet) marker
*/
/**************************************************************************/
Expand Down Expand Up @@ -123,17 +126,19 @@ uint32_t cobsEncodedLength(const uint8_t *ptr, uint32_t length)
@param length Length of the data to encode

@return The max length required to encode the data

@note Since the contents of the buffer are unknown, then we must assume
that the entire buffer has no end-of-packet markers. This would
require the injection of overhead bytes (as opposed to the
replacement of end-of-packet markers with overhead bytes) at
intervals of 255, thus producing the worst case scenario.
@note An additional byte is added for the EOP (end-of-packet) marker.
*/
/**************************************************************************/
uint32_t cobsEncodedMaxLength(uint32_t length)
{
const uint32_t overheadBytes = ((length / 254) + ((length % 254) > 0));
return (length + overheadBytes);
return (length + overheadBytes + COBS_EOP_OVERHEAD);
}

//**************************************************************************/
Expand All @@ -144,12 +149,13 @@ uint32_t cobsEncodedMaxLength(uint32_t length)
@param bufLen Length of the buffer in bytes

@return the length of unencoded data
@note The computation may leave additional space at the end, including one
byte for the EOP (end-of-packet) marker.

@note The computation may leave additional space at the end.
@note An additional byte is added for the EOP (end-of-packet) marker.
*/
/**************************************************************************/
uint32_t cobsGuaranteedFit(uint32_t bufLen)
{
uint32_t cobsOverhead = 1 + (bufLen / 254) + 1;
uint32_t cobsOverhead = 1 + (bufLen / 254) + COBS_EOP_OVERHEAD;
return (cobsOverhead > bufLen ? 0 : (bufLen - cobsOverhead));
}
Loading
Loading