asrt
Automated System Runtime Testing library
Loading...
Searching...
No Matches
cobs.h
1
12#ifndef ASRT_COBS_H
13#define ASRT_COBS_H
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#include "./asrt_assert.h"
20#include "./span.h"
21#include "./status.h"
22
23#include <stdint.h>
24
27{
28 uint8_t* offset;
29 uint8_t* p;
30};
31
33static inline void asrt_cobs_encoder_init( struct asrt_cobs_encoder* e, uint8_t* buffer )
34{
35 ASRT_ASSERT( e );
36 e->offset = buffer;
37 e->p = buffer;
38 *e->offset = 1;
39 e->p++;
40}
41
44void asrt_cobs_encoder_iter( struct asrt_cobs_encoder* e, uint8_t b );
45
48enum asrt_status asrt_cobs_encode_buffer( struct asrt_span in, struct asrt_span* out );
49
52{
53 uint8_t iszero;
54 uint8_t offset;
55};
56
57static inline void asrt_cobs_decoder_init( struct asrt_cobs_decoder* d )
58{
59 ASRT_ASSERT( d );
60 d->iszero = 0;
61 d->offset = 1;
62}
63
65void asrt_cobs_decoder_iter( struct asrt_cobs_decoder* d, uint8_t b, uint8_t** p );
66
69{
70 struct asrt_span buff;
71 struct asrt_span used;
72};
73
74static inline void asrt_cobs_ibuffer_init( struct asrt_cobs_ibuffer* b, struct asrt_span sp )
75{
76 ASRT_ASSERT( b );
77 b->buff = sp;
78 b->used = ( struct asrt_span ){ .b = sp.b, .e = sp.b };
79}
80
82enum asrt_status asrt_cobs_ibuffer_insert( struct asrt_cobs_ibuffer* b, struct asrt_span sp );
83
90int8_t asrt_cobs_ibuffer_iter( struct asrt_cobs_ibuffer* b, struct asrt_span* buff );
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif
Stateful COBS decoder. Maintains position within current code block.
Definition: cobs.h:52
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: cobs.h:27
Input buffer for COBS-encoded data. buff is total capacity, used is occupied region.
Definition: cobs.h:69
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: span.h:23
uint8_t * b
Pointer to the first byte.
Definition: span.h:24