Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
multipass
Commits
ee720ed3
Commit
ee720ed3
authored
6 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
prototest: json serialization
parent
96462e6b
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+4
-0
4 additions, 0 deletions
Makefile
include/object/outputstream.h
+7
-0
7 additions, 0 deletions
include/object/outputstream.h
src/app/prototest/main.cc
+43
-3
43 additions, 3 deletions
src/app/prototest/main.cc
src/os/object/outputstream.cc
+10
-0
10 additions, 0 deletions
src/os/object/outputstream.cc
with
64 additions
and
3 deletions
Makefile
+
4
−
0
View file @
ee720ed3
...
...
@@ -116,6 +116,10 @@ ifeq (${wakeup}, 1)
COMMON_FLAGS
+=
-DWITH_WAKEUP
endif
ifeq
(${ostream}, 1)
COMMON_FLAGS
+=
-DWITH_OSTREAM
endif
include
src/arch/${arch}/Makefile.inc
clean
:
arch_clean
...
...
This diff is collapsed.
Click to expand it.
include/object/outputstream.h
+
7
−
0
View file @
ee720ed3
...
...
@@ -2,6 +2,9 @@
#define OUTPUTSTREAM_H
#include
<stdint.h>
#ifdef WITH_OSTREAM
#include
<ostream>
#endif
class
OutputStream
{
private:
...
...
@@ -39,6 +42,10 @@ class OutputStream {
OutputStream
&
operator
<<
(
double
number
);
OutputStream
&
operator
<<
(
OutputStream
&
(
*
fun
)
(
OutputStream
&
));
#ifdef WITH_OSTREAM
OutputStream
&
operator
<<
(
std
::
string
s
);
#endif
void
setBase
(
uint8_t
b
);
void
printf_uint8
(
uint8_t
num
);
void
printf_float
(
float
num
);
...
...
This diff is collapsed.
Click to expand it.
src/app/prototest/main.cc
+
43
−
3
View file @
ee720ed3
...
...
@@ -9,15 +9,48 @@
char
buf
[
256
];
// TODOs
//
// Code -> JSON
// Code -> XDR
// Code -> MsgPack
// Code -> ProtoBuf
// Code -> CBOR
//
// JSON -> Code/Data
// XDR -> Code/Data
// MsgPack -> Code/Data
// ProtoBuf -> Code/Data
// CBOR -> Code/Data
void
loop
(
void
)
{
static
unsigned
int
ts
=
0
;
char
json
[]
=
"{
\"
sensor
\"
:
\"
gps
\"
,
\"
time
\"
:1351824120,
\"
data
\"
:[48.756080,2.302038]}"
;
ArduinoJson
::
StaticJsonBuffer
<
200
>
jsonBuffer
;
ArduinoJson
::
JsonObject
&
root
=
jsonBuffer
.
parseObject
(
json
);
const
char
*
sensor
=
root
[
"sensor"
];
kout
<<
"sensor: "
<<
sensor
<<
endl
;
/*
* nlohmann modernjson serialization
*/
nlohmann
::
json
js1
;
js1
[
"sensor"
]
=
"gps"
;
js1
[
"time"
]
=
ts
;
js1
[
"data"
]
=
{
48.756080
,
2.302038
};
kout
<<
js1
.
dump
()
<<
endl
;
nlohmann
::
json
js2
=
{
{
"sensor"
,
"gps"
},
{
"time"
,
ts
},
{
"data"
,
{
48.756080
,
2.302038
}
}
};
kout
<<
js2
.
dump
()
<<
endl
;
nlohmann
::
json
j
=
R"({"compact": true, "schema": 0})"
_json
;
j
[
"ts"
]
=
ts
;
std
::
vector
<
std
::
uint8_t
>
v_cbor
=
nlohmann
::
json
::
to_cbor
(
j
);
kout
<<
"CBOR vector is "
<<
hex
;
...
...
@@ -26,15 +59,21 @@ void loop(void)
}
kout
<<
endl
;
kout
<<
"manual JSON: {
\"
sensor
\"
:
\"
gps
\"
,
\"
time
\"
:"
<<
dec
<<
1351824120
;
kout
<<
"manual JSON: {
\"
sensor
\"
:
\"
gps
\"
,
\"
time
\"
:"
<<
dec
<<
ts
;
kout
<<
",
\"
data
\"
:["
<<
48.756080
<<
","
<<
2.302038
<<
"]}"
<<
endl
;
/*
* nlohmann modernjson deserialization
*/
auto
jd1
=
R"({"compact": true, "schema": 0})"
_json
;
BufferOutput
<
XDRStream
>
foostream
(
buf
);
XDRInput
input
(
buf
);
char
test
[]
=
"Obai World!"
;
foostream
<<
123
<<
-
2
<<
123456
<<
0
<<
4294967296
<<
0
;
foostream
<<
123
<<
-
2
<<
ts
<<
0
<<
4294967296
<<
0
;
foostream
.
setNextArrayLen
(
3
);
foostream
<<
fixed
<<
"Hai"
;
foostream
.
setNextArrayLen
(
sizeof
(
test
));
...
...
@@ -50,7 +89,7 @@ void loop(void)
kout
<<
dec
;
kout
<<
"foostream = "
<<
input
.
get_uint32
()
<<
" = "
<<
123
;
kout
<<
", "
<<
input
.
get_int32
()
<<
" = "
<<
-
2
;
kout
<<
", "
<<
input
.
get_uint32
()
<<
" = "
<<
123456
;
kout
<<
", "
<<
input
.
get_uint32
()
<<
" = "
<<
ts
;
kout
<<
", "
<<
input
.
get_uint32
();
kout
<<
", "
<<
input
.
get_uint64
();
kout
<<
", "
<<
input
.
get_uint32
();
...
...
@@ -63,6 +102,7 @@ void loop(void)
#ifdef TIMER_S
kout
<<
dec
<<
uptime
.
get_s
()
<<
endl
;
#endif
ts
++
;
}
int
main
(
void
)
...
...
This diff is collapsed.
Click to expand it.
src/os/object/outputstream.cc
+
10
−
0
View file @
ee720ed3
...
...
@@ -140,6 +140,16 @@ OutputStream & OutputStream::operator<<(OutputStream & (*fkt) (OutputStream &))
return
fkt
(
*
this
);
}
#ifdef WITH_OSTREAM
OutputStream
&
OutputStream
::
operator
<<
(
std
::
string
s
)
{
for
(
auto
c
:
s
)
{
put
(
c
);
}
return
*
this
;
}
#endif
void
OutputStream
::
setBase
(
uint8_t
b
)
{
if
(
b
==
2
||
b
==
8
||
b
==
10
||
b
==
16
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment