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
23
enum
SenMLCborDataType
{};
24
25
#define SENML_CBOR_KEY 1
26
#define SENML_CBOR_VALUE 2
27
31
class
SenMLCborParser
:
public
SenMLBaseParser
{
32
33
public
:
34
SenMLCborParser
(
SenMLBasePack
*
root
,
SenMLStreamMethod
format) :
SenMLBaseParser
(
root
), state(0) {
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
SenMLBasePack
Definition:
senml_basepack.h:24
SenMLBaseParser
Definition:
senml_base_parser.h:24
SenMLBaseParser::root
SenMLBasePack * root
Definition:
senml_base_parser.h:27
SenMLCborParser
Definition:
senml_cbor_parser.h:31
SenMLCborParser::parse
void parse(Stream *source)
Definition:
senml_cbor_parser.cpp:18
SenMLCborParser::SenMLCborParser
SenMLCborParser(SenMLBasePack *root, SenMLStreamMethod format)
Definition:
senml_cbor_parser.h:34
Stream
Definition:
defaults.h:50
senml_base_parser.h
SenMLCborDataType
SenMLCborDataType
Definition:
senml_cbor_parser.h:23
senml_enums.h
SenMLStreamMethod
SenMLStreamMethod
Definition:
senml_enums.h:49
SenMLDataType
SenMLDataType
Definition:
senml_enums.h:25
_streamCtx
StreamContext * _streamCtx
Definition:
senml_helpers.cpp:27
senml_helpers.h
senml_logging.h
StreamContext_t
Definition:
senml_helpers.h:55
StreamContext_t::baseValue
BaseData baseValue
Definition:
senml_helpers.h:61
StreamContext_t::baseSum
BaseData baseSum
Definition:
senml_helpers.h:62
StreamContext_t::format
SenMLStreamMethod format
Definition:
senml_helpers.h:60
BaseData_t::baseUint
uint64_t baseUint
Definition:
senml_helpers.h:29
src
senml
senml_cbor_parser.h
Generated by
1.9.3