vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / main / common / streambuf.h
blob74331147da88e16f20a9c98e323e40abdf466a3c
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight 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.
9 * Cleanflight 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.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include <stdbool.h>
21 #include <stdint.h>
23 // simple buffer-based serializer/deserializer without implicit size check
24 // little-endian encoding implemneted now
26 typedef struct sbuf_s {
27 uint8_t *ptr; // data pointer must be first (sbuff_t* is equivalent to uint8_t **)
28 uint8_t *end;
29 } sbuf_t;
31 sbuf_t *sbufInit(sbuf_t *sbuf, uint8_t *ptr, uint8_t *end);
33 void sbufWriteU8(sbuf_t *dst, uint8_t val);
34 void sbufWriteU16(sbuf_t *dst, uint16_t val);
35 void sbufWriteU32(sbuf_t *dst, uint32_t val);
36 void sbufFill(sbuf_t *dst, uint8_t data, int len);
37 void sbufWriteData(sbuf_t *dst, const void *data, int len);
38 bool sbufWriteDataSafe(sbuf_t *dst, const void *data, int len);
39 void sbufWriteString(sbuf_t *dst, const char *string);
40 void sbufWriteStringWithZeroTerminator(sbuf_t *dst, const char *string);
41 void sbufWriteU16BigEndian(sbuf_t *dst, uint16_t val);
42 void sbufWriteU32BigEndian(sbuf_t *dst, uint32_t val);
44 uint8_t sbufReadU8(sbuf_t *src);
45 uint16_t sbufReadU16(sbuf_t *src);
46 uint32_t sbufReadU32(sbuf_t *src);
47 void sbufReadData(const sbuf_t *dst, void *data, int len);
49 bool sbufReadU8Safe(uint8_t *dst, sbuf_t *src);
50 bool sbufReadU16Safe(uint16_t *dst, sbuf_t *src);
51 bool sbufReadU32Safe(uint32_t *dst, sbuf_t *src);
52 bool sbufReadI8Safe(int8_t *dst, sbuf_t *src);
53 bool sbufReadI16Safe(int16_t *dst, sbuf_t *src);
54 bool sbufReadI32Safe(int32_t *dst, sbuf_t *src);
55 bool sbufReadDataSafe(const sbuf_t *src, void *data, int len);
57 int sbufBytesRemaining(const sbuf_t *buf);
58 uint8_t* sbufPtr(sbuf_t *buf);
59 const uint8_t* sbufConstPtr(const sbuf_t *buf);
60 void sbufAdvance(sbuf_t *buf, int size);
62 void sbufSwitchToReader(sbuf_t *buf, uint8_t * base);