scsl 0.1.1
Shimmering Clarity Standard Library
TLV.h
Go to the documentation of this file.
1
13
14#ifndef KIMODEM_TLV_H
15#define KIMODEM_TLV_H
16
17#include <cstdint>
18#include <array>
19
20#include "Arena.h"
21
22
23namespace scsl {
24namespace TLV {
25
26#ifndef TLV_MAX_LEN
27static constexpr size_t TLV_MAX_LEN = 253;
28#endif
29
30static constexpr uint8_t TAG_EMPTY = 0;
31
32
39struct Record {
41 uint8_t Tag;
43 uint8_t Len;
45 uint8_t Val[TLV_MAX_LEN];
46};
47
55uint8_t *WriteToMemory(Arena &arena, uint8_t *cursor, Record &rec);
56
61void ReadFromMemory(Record &rec, uint8_t *cursor);
62
69void SetRecord(Record &rec, uint8_t tag, uint8_t length, const char *data);
70
73void DeleteRecord(Arena &arena, uint8_t *cursor);
74
75/*
76* returns a pointer to memory where the record was found,
77* e.g. LocateTag(...)[0] is the tag of the found record.
78* FindTag will call LocateTag and then SkipRecord if the
79* tag was found.
80*/
92uint8_t *FindTag(Arena &arena, uint8_t *cursor, Record &rec);
93
103uint8_t *LocateTag(Arena &arena, uint8_t *cursor, Record &rec);
104
115uint8_t *FindEmpty(Arena &arena, uint8_t *cursor);
116
122uint8_t *SkipRecord(Record &rec, uint8_t *cursor);
123
124
125} // namespace TLV
126} // namespace scsl
127
128
129#endif
Memory management using an arena.
void SetRecord(Record &rec, uint8_t tag, uint8_t length, const char *data)
Definition: TLV.cc:65
uint8_t * WriteToMemory(Arena &arena, uint8_t *cursor, Record &rec)
Definition: TLV.cc:34
uint8_t * LocateTag(Arena &arena, uint8_t *cursor, Record &rec)
Definition: TLV.cc:101
void DeleteRecord(Arena &arena, uint8_t *cursor)
Definition: TLV.cc:147
void ReadFromMemory(Record &rec, uint8_t *cursor)
Definition: TLV.cc:75
uint8_t * FindTag(Arena &arena, uint8_t *cursor, Record &rec)
Definition: TLV.cc:89
uint8_t * SkipRecord(Record &rec, uint8_t *cursor)
Definition: TLV.cc:140
uint8_t * FindEmpty(Arena &arena, uint8_t *cursor)
Definition: TLV.cc:130
Definition: Arena.h:65
scsl is the top-level namespace containing all the code in this library.
Definition: scsl.h:37
Definition: TLV.h:39
uint8_t Tag
A Tag is used to identify the type of this record.
Definition: TLV.h:41
uint8_t Len
Len describes the number of bytes stored in Val.
Definition: TLV.h:43
uint8_t Val[TLV_MAX_LEN]
Val contains the data in the record.
Definition: TLV.h:45