NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
streambuf.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include <stdint.h>
21 
22 // simple buffer-based serializer/deserializer without implicit size check
23 // little-endian encoding implemneted now
24 
25 typedef struct sbuf_s {
26  uint8_t *ptr; // data pointer must be first (sbuff_t* is equivalent to uint8_t **)
27  uint8_t *end;
28 } sbuf_t;
29 
30 void sbufWriteU8(sbuf_t *dst, uint8_t val);
31 void sbufWriteU16(sbuf_t *dst, uint16_t val);
32 void sbufWriteU32(sbuf_t *dst, uint32_t val);
33 void sbufWriteData(sbuf_t *dst, const void *data, int len);
34 void sbufWriteString(sbuf_t *dst, const char *string);
35 
36 uint8_t sbufReadU8(sbuf_t *src);
37 uint16_t sbufReadU16(sbuf_t *src);
38 uint32_t sbufReadU32(sbuf_t *src);
39 void sbufReadData(sbuf_t *dst, void *data, int len);
40 
41 int sbufBytesRemaining(sbuf_t *buf);
42 uint8_t* sbufPtr(sbuf_t *buf);
43 void sbufAdvance(sbuf_t *buf, int size);
44 
45 void sbufSwitchToReader(sbuf_t *buf, uint8_t * base);
void sbufReadData(sbuf_t *dst, void *data, int len)
Definition: streambuf.c:76
int sbufBytesRemaining(sbuf_t *buf)
Definition: streambuf.c:83
void sbufAdvance(sbuf_t *buf, int size)
Definition: streambuf.c:96
void sbufWriteU32(sbuf_t *dst, uint32_t val)
Definition: streambuf.c:34
uint32_t sbufReadU32(sbuf_t *src)
Definition: streambuf.c:66
void sbufWriteData(sbuf_t *dst, const void *data, int len)
Definition: streambuf.c:42
uint16_t sbufReadU16(sbuf_t *src)
Definition: streambuf.c:58
void sbufSwitchToReader(sbuf_t *buf, uint8_t *base)
Definition: streambuf.c:102
Definition: streambuf.h:25
uint8_t sbufReadU8(sbuf_t *src)
Definition: streambuf.c:53
uint8_t * end
Definition: streambuf.h:27
void sbufWriteString(sbuf_t *dst, const char *string)
Definition: streambuf.c:48
uint8_t * ptr
Definition: streambuf.h:26
struct sbuf_s sbuf_t
uint8_t * sbufPtr(sbuf_t *buf)
Definition: streambuf.c:88
void sbufWriteU8(sbuf_t *dst, uint8_t val)
Definition: streambuf.c:23
void sbufWriteU16(sbuf_t *dst, uint16_t val)
Definition: streambuf.c:28
uint16_t data
Definition: config.c:91