-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcobs.h
More file actions
29 lines (21 loc) · 823 Bytes
/
Copy pathcobs.h
File metadata and controls
29 lines (21 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SPDX-Copyright-Text: 2025 Julian Scheffers
// SPDX-License-Identifier: MIT
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// Calculates how long some binary data could maximally be when COBS-encoded.
#define COBS_ENCODED_MAX_LENGTH(len) ((len) + (((len) + 253) / 254) + 1)
// Calculates how long some binary data could maximally be when COBS-decoded.
#define COBS_DECODED_MAX_LENGTH(len) ((len) - 1)
// Encode some binary data with COBS.
// Adds a null-terminator at the end of the output.
size_t cobs_encode(uint8_t* output, uint8_t const* input, size_t input_len);
// Decode some binary data with COBS.
// Assumes the null-terminator is still present.
size_t cobs_decode(uint8_t* output, uint8_t const* input, size_t input_len);
#ifdef __cplusplus
}
#endif