Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Astri Packet
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
Package Registry
Container 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
BIAS
Packets
Astri Packet
Commits
22113dbd
Commit
22113dbd
authored
1 year ago
by
Valerio Pastore
Browse files
Options
Downloads
Patches
Plain Diff
removed unordered_json
parent
42cfed79
No related branches found
No related tags found
1 merge request
!2
removed unordered_json
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/PacketStructureJson.h
+1
-1
1 addition, 1 deletion
include/PacketStructureJson.h
src/PacketStructureJson.cpp
+23
-13
23 additions, 13 deletions
src/PacketStructureJson.cpp
with
24 additions
and
14 deletions
include/PacketStructureJson.h
+
1
−
1
View file @
22113dbd
...
...
@@ -17,7 +17,7 @@ namespace inaf::oasbo::Packets {
class
PacketStructureJson
:
public
inaf
::
oasbo
::
PacketLib
::
BasePacketStructure
{
protected:
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
convertToTupleVector
(
const
nlohmann
::
ordered_
json
&
data
,
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
convertToTupleVector
(
const
nlohmann
::
json
&
data
,
uint
&
count
);
public:
...
...
This diff is collapsed.
Click to expand it.
src/PacketStructureJson.cpp
+
23
−
13
View file @
22113dbd
...
...
@@ -17,7 +17,7 @@ std::vector<std::tuple<uint, std::string, uint>> PacketStructureJson::readStruct
exit
(
EXIT_FAILURE
);
}
uint
count
=
0
;
nlohmann
::
ordered_
json
data
;
nlohmann
::
json
data
;
file
>>
data
;
this
->
structure
=
convertToTupleVector
(
data
,
count
);
file
.
close
();
...
...
@@ -25,19 +25,29 @@ std::vector<std::tuple<uint, std::string, uint>> PacketStructureJson::readStruct
}
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
PacketStructureJson
::
convertToTupleVector
(
const
nlohmann
::
ordered_
json
&
data
,
uint
&
count
)
{
const
nlohmann
::
json
&
data
,
uint
&
count
)
{
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
out
;
for
(
auto
it
=
data
.
begin
();
it
!=
data
.
end
();
++
it
)
{
if
(
it
.
value
().
is_object
())
{
if
(
!
it
.
value
().
count
(
"size"
)
||
!
it
.
value
().
count
(
"fields"
)
||
it
.
value
().
size
()
!=
2
)
{
std
::
cerr
<<
"Error in file: "
<<
it
.
value
().
dump
()
std
::
vector
<
std
::
string
>
keys
;
// Helper vectors to preserve the fields order in the file
std
::
vector
<
nlohmann
::
json
>
values
;
for
(
auto
&
element
:
data
.
items
())
{
keys
.
push_back
(
element
.
key
());
values
.
push_back
(
element
.
value
());
}
for
(
size_t
i
=
0
;
i
<
keys
.
size
();
++
i
)
{
if
(
values
[
i
].
is_object
())
{
if
(
!
values
[
i
].
count
(
"size"
)
||
!
values
[
i
].
count
(
"fields"
)
||
values
[
i
].
size
()
!=
2
)
{
std
::
cerr
<<
"Error in file: "
<<
values
[
i
].
dump
()
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
for
(
uint
i
=
0
;
i
<
it
.
value
()
[
"size"
];
i
++
)
{
for
(
uint
i
=
0
;
i
<
value
s
[
i
]
[
"size"
];
i
++
)
{
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
subArray
=
convertToTupleVector
(
it
.
value
()
[
"fields"
],
count
);
convertToTupleVector
(
value
s
[
i
]
[
"fields"
],
count
);
std
::
for_each
(
subArray
.
begin
(),
subArray
.
end
(),
[
i
](
std
::
tuple
<
uint
,
std
::
string
,
uint
>
&
line
)
{
std
::
get
<
1
...
...
@@ -47,15 +57,15 @@ std::vector<std::tuple<uint, std::string, uint>> PacketStructureJson::convertToT
out
.
insert
(
out
.
end
(),
subArray
.
begin
(),
subArray
.
end
());
}
}
else
{
if
(
!
it
.
value
()
.
is_number_integer
())
{
std
::
cerr
<<
"Error in value, not an int: "
<<
it
.
value
()
.
dump
()
if
(
!
value
s
[
i
]
.
is_number_integer
())
{
std
::
cerr
<<
"Error in value, not an int: "
<<
value
s
[
i
]
.
dump
()
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
std
::
string
fieldName
(
it
.
key
()
);
std
::
string
fieldName
(
keys
[
i
]
);
std
::
transform
(
fieldName
.
begin
(),
fieldName
.
end
(),
fieldName
.
begin
(),
::
tolower
);
out
.
push_back
(
std
::
make_tuple
(
count
,
fieldName
,
it
.
value
()
));
out
.
push_back
(
std
::
make_tuple
(
count
,
fieldName
,
value
s
[
i
]
));
count
+=
1
;
}
}
...
...
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