scsl  1.1.1
Shimmering Clarity Standard Library
TLV.h
Go to the documentation of this file.
1 
14 #ifndef KIMODEM_TLV_H
15 #define KIMODEM_TLV_H
16 
17 #include <array>
18 #include <cstdint>
19 
20 #include "Arena.h"
21 
22 
23 namespace scsl {
24 
26 namespace TLV {
27 
28 
29 #ifndef TLV_MAX_LEN
30 static constexpr size_t TLV_MAX_LEN = 253;
31 #endif
32 
33 static constexpr uint8_t TAG_EMPTY = 0;
34 
35 
42 struct Record {
44  uint8_t Tag;
46  uint8_t Len;
48  uint8_t Val[TLV_MAX_LEN];
49 };
50 
58 uint8_t *WriteToMemory(Arena &arena, uint8_t *cursor, Record &rec);
59 
64 void ReadFromMemory(Record &rec, uint8_t *cursor);
65 
72 void SetRecord(Record &rec, uint8_t tag, uint8_t length, const char *data);
73 
76 void DeleteRecord(Arena &arena, uint8_t *cursor);
77 
78 /*
79 * returns a pointer to memory where the record was found,
80 * e.g. LocateTag(...)[0] is the tag of the found record.
81 * FindTag will call LocateTag and then SkipRecord if the
82 * tag was found.
83 */
95 uint8_t *FindTag(Arena &arena, uint8_t *cursor, Record &rec);
96 
106 uint8_t *LocateTag(Arena &arena, uint8_t *cursor, Record &rec);
107 
118 uint8_t *FindEmpty(Arena &arena, uint8_t *cursor);
119 
125 uint8_t *SkipRecord(Record &rec, uint8_t *cursor);
126 
127 
128 } // namespace TLV
129 } // namespace scsl
130 
131 
132 #endif
Memory management using an arena.
Fixed, pre-allocated memory.
Definition: Arena.h:74
void SetRecord(Record &rec, uint8_t tag, uint8_t length, const char *data)
uint8_t * FindTag(Arena &arena, uint8_t *cursor, Record &rec)
void DeleteRecord(Arena &arena, uint8_t *cursor)
uint8_t * SkipRecord(Record &rec, uint8_t *cursor)
void ReadFromMemory(Record &rec, uint8_t *cursor)
uint8_t * WriteToMemory(Arena &arena, uint8_t *cursor, Record &rec)
uint8_t * LocateTag(Arena &arena, uint8_t *cursor, Record &rec)
uint8_t * FindEmpty(Arena &arena, uint8_t *cursor)
scsl is the top-level namespace containing all the code in this library.
Definition: scsl.h:43
Tag-length-value record with single byte tags and lengths.
Definition: TLV.h:42
uint8_t Tag
A Tag is used to identify the type of this record.
Definition: TLV.h:44
uint8_t Len
Len describes the number of bytes stored in Val.
Definition: TLV.h:46
uint8_t Val[TLV_MAX_LEN]
Val contains the data in the record.
Definition: TLV.h:48