scsl  0.2.0
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 namespace TLV {
25 
26 
27 #ifndef TLV_MAX_LEN
28 static constexpr size_t TLV_MAX_LEN = 253;
29 #endif
30 
31 static constexpr uint8_t TAG_EMPTY = 0;
32 
33 
40 struct Record {
42  uint8_t Tag;
44  uint8_t Len;
46  uint8_t Val[TLV_MAX_LEN];
47 };
48 
56 uint8_t *WriteToMemory(Arena &arena, uint8_t *cursor, Record &rec);
57 
62 void ReadFromMemory(Record &rec, uint8_t *cursor);
63 
70 void SetRecord(Record &rec, uint8_t tag, uint8_t length, const char *data);
71 
74 void DeleteRecord(Arena &arena, uint8_t *cursor);
75 
76 /*
77 * returns a pointer to memory where the record was found,
78 * e.g. LocateTag(...)[0] is the tag of the found record.
79 * FindTag will call LocateTag and then SkipRecord if the
80 * tag was found.
81 */
93 uint8_t *FindTag(Arena &arena, uint8_t *cursor, Record &rec);
94 
104 uint8_t *LocateTag(Arena &arena, uint8_t *cursor, Record &rec);
105 
116 uint8_t *FindEmpty(Arena &arena, uint8_t *cursor);
117 
123 uint8_t *SkipRecord(Record &rec, uint8_t *cursor);
124 
125 
126 } // namespace TLV
127 } // namespace scsl
128 
129 
130 #endif
Memory management using an arena.
void SetRecord(Record &rec, uint8_t tag, uint8_t length, const char *data)
Definition: TLV.cc:91
uint8_t * WriteToMemory(Arena &arena, uint8_t *cursor, Record &rec)
Definition: TLV.cc:60
uint8_t * LocateTag(Arena &arena, uint8_t *cursor, Record &rec)
Definition: TLV.cc:128
void DeleteRecord(Arena &arena, uint8_t *cursor)
Definition: TLV.cc:183
void ReadFromMemory(Record &rec, uint8_t *cursor)
Definition: TLV.cc:101
uint8_t * FindTag(Arena &arena, uint8_t *cursor, Record &rec)
Definition: TLV.cc:115
uint8_t * SkipRecord(Record &rec, uint8_t *cursor)
Definition: TLV.cc:176
uint8_t * FindEmpty(Arena &arena, uint8_t *cursor)
Definition: TLV.cc:166
Definition: Arena.h:80
scsl is the top-level namespace containing all the code in this library.
Definition: scsl.h:43
Definition: TLV.h:40
uint8_t Tag
A Tag is used to identify the type of this record.
Definition: TLV.h:42
uint8_t Len
Len describes the number of bytes stored in Val.
Definition: TLV.h:44
uint8_t Val[TLV_MAX_LEN]
Val contains the data in the record.
Definition: TLV.h:46