KPN Things Device SDK
senml_cbor_parser.h
Go to the documentation of this file.
1/* _ __ ____ _ _
2 * | |/ / | _ \ | \ | |
3 * | ' / | |_) | | \| |
4 * | . \ | __/ | |\ |
5 * |_|\_\ |_| |_| \_|
6 *
7 * (c) 2020 KPN
8 * License: MIT License.
9 * Author: Joseph Verburg, Jan Bogaerts
10 *
11 * parse cbor header
12 */
13
14#ifndef THINGSML_SENML_CBOR_PARSER
15#define THINGSML_SENML_CBOR_PARSER
16
17#include "../cbor/cbor.h"
18#include "senml_base_parser.h"
19#include "senml_enums.h"
20#include "senml_helpers.h"
21#include "senml_logging.h"
22
24
25#define SENML_CBOR_KEY 1
26#define SENML_CBOR_VALUE 2
27
32
33 public:
35 this->ctx.format = format;
36 this->ctx.baseValue.baseUint = 0; // init to 0, so we get correct results for first element as well.
37 this->ctx.baseSum.baseUint = 0;
38 _streamCtx = &this->ctx; // set the global variable so that we don't have to pass it along on the stack all the
39 // time (saves mem & codesize)
40 };
41
42 // convert the cbor raw data into senml and actuate the records in the root pack.
43 void parse(Stream *source);
44
45 void parse(char *source, int length);
46
47 private:
48 unsigned char state; // keeps track of the current parse state
49 int curLabel; // the cbor number that represents the current senml label (unit, value, boolvalue, basename,..). The
50 // next item to read has to be the value for the label
51 StreamContext ctx;
52
53
54 void setValue(void *value, int length, SenMLDataType type);
55 void setBinaryValue(const char *value, int length);
56 void processDouble(double value);
57
58 void internalParse();
59
60 size_t processBytes(SenMLDataType type);
61
62 size_t parseNext();
63
64 size_t processUnsignedInt();
65 size_t processInt();
66
67 size_t processArray();
68 size_t processMap();
69
70};
71
72#endif // THINGSML_SENML_CBOR_PARSER
Definition: senml_basepack.h:24
Definition: senml_base_parser.h:24
SenMLBasePack * root
Definition: senml_base_parser.h:27
Definition: senml_cbor_parser.h:31
void parse(Stream *source)
Definition: senml_cbor_parser.cpp:18
SenMLCborParser(SenMLBasePack *root, SenMLStreamMethod format)
Definition: senml_cbor_parser.h:34
Definition: defaults.h:50
SenMLCborDataType
Definition: senml_cbor_parser.h:23
SenMLStreamMethod
Definition: senml_enums.h:49
SenMLDataType
Definition: senml_enums.h:25
StreamContext * _streamCtx
Definition: senml_helpers.cpp:27
Definition: senml_helpers.h:55
BaseData baseValue
Definition: senml_helpers.h:61
BaseData baseSum
Definition: senml_helpers.h:62
SenMLStreamMethod format
Definition: senml_helpers.h:60
uint64_t baseUint
Definition: senml_helpers.h:29