forked from Yurik72/ESPHap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlv.h
49 lines (36 loc) · 1.19 KB
/
tlv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef __TLV_H__
#define __TLV_H__
#include "port_x.h"
#ifdef ARDUINO8266_SERVER_CPP
#ifdef __cplusplus
extern "C" {
#endif
#endif
typedef unsigned char byte;
typedef struct _tlv {
struct _tlv *next;
byte type;
byte *value;
size_t size;
} tlv_t;
typedef struct {
tlv_t *head;
} tlv_values_t;
void set_tlv_allocator_buffer(void* b, size_t size);
tlv_values_t *tlv_new();
void tlv_free(tlv_values_t *values);
int tlv_add_value(tlv_values_t *values, byte type, const byte *value, size_t size);
int tlv_add_string_value(tlv_values_t *values, byte type, const char *value);
int tlv_add_integer_value(tlv_values_t *values, byte type, size_t size, int value);
int tlv_add_tlv_value(tlv_values_t *values, byte type, tlv_values_t *value);
tlv_t *tlv_get_value(const tlv_values_t *values, byte type);
int tlv_get_integer_value(const tlv_values_t *values, byte type, int def);
tlv_values_t *tlv_get_tlv_value(const tlv_values_t *values, byte type);
int tlv_format(const tlv_values_t *values, byte *buffer, size_t *size);
int tlv_parse(const byte *buffer, size_t length, tlv_values_t *values);
#ifdef ARDUINO8266_SERVER_CPP
#ifdef __cplusplus
} //extern C
#endif
#endif
#endif // __TLV_H__