FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
here-data-sdk-cpp/tests/common/ReadDefaultResponses.cpp at master · heremaps/here-data-sdk-cpp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
heremaps
/
here-data-sdk-cpp
Public
Notifications
You must be signed in to change notification settings
Fork
48
Star
54
Code
Issues
2
Pull requests
20
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
here-data-sdk-cpp
/
tests
/
common
/
ReadDefaultResponses.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
227 lines (186 loc) · 7.61 KB
Breadcrumbs
here-data-sdk-cpp
/
tests
/
common
/
ReadDefaultResponses.cpp
Copy path
File metadata and controls
227 lines (186 loc) · 7.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* Copyright (C) 2020-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/
#
include
"
ReadDefaultResponses.h
"
#
include
<
numeric
>
#
include
<
string
>
#
include
<
utility
>
#
include
<
vector
>
#
include
<
generated/serializer/SerializerWrapper.h
>
#
include
<
boost/json/serialize.hpp
>
#
include
<
boost/json/value.hpp
>
namespace
{
void
WriteSubquadsToJson
(
boost::json::object& doc,
const
olp::geo::TileKey& root_tile,
const
std::map<std::
uint64_t
, mockserver::TileMetadata>& sub_quads) {
boost::json::array sub_quads_value;
for
(
const
auto
& quad : sub_quads) {
const
mockserver::TileMetadata& metadata = quad.
second
;
const
auto
partition = root_tile.
AddedSubkey64
(quad.
first
).
ToHereTile
();
boost::json::object item;
olp::serializer::serialize
(
"
subQuadKey
"
,
std::to_string
(quad.
first
), item);
olp::serializer::serialize
(
"
version
"
, metadata.
version
, item);
olp::serializer::serialize
(
"
dataHandle
"
, metadata.
data_handle
, item);
olp::serializer::serialize
(
"
crc
"
, metadata.
crc
, item);
olp::serializer::serialize
(
"
checksum
"
, metadata.
checksum
, item);
olp::serializer::serialize
(
"
dataSize
"
, metadata.
data_size
, item);
olp::serializer::serialize
(
"
compressedDataSize
"
,
metadata.
compressed_data_size
, item);
sub_quads_value.
emplace_back
(
std::move
(item));
}
doc.
emplace
(
"
subQuads
"
,
std::move
(sub_quads_value));
}
void
WriteParentquadsToJson
(
boost::json::object& doc,
const
std::map<std::
uint64_t
, mockserver::TileMetadata>& parent_quads) {
boost::json::array parent_quads_value;
for
(
const
auto
& parent : parent_quads) {
const
auto
partition =
std::to_string
(parent.
first
);
const
mockserver::TileMetadata& metadata = parent.
second
;
boost::json::object item;
olp::serializer::serialize
(
"
partition
"
, partition, item);
olp::serializer::serialize
(
"
version
"
, metadata.
version
, item);
olp::serializer::serialize
(
"
dataHandle
"
, metadata.
data_handle
, item);
olp::serializer::serialize
(
"
crc
"
, metadata.
crc
, item);
olp::serializer::serialize
(
"
checksum
"
, metadata.
checksum
, item);
olp::serializer::serialize
(
"
dataSize
"
, metadata.
data_size
, item);
olp::serializer::serialize
(
"
compressedDataSize
"
,
metadata.
compressed_data_size
, item);
parent_quads_value.
emplace_back
(
std::move
(item));
}
doc.
emplace
(
"
parentQuads
"
,
std::move
(parent_quads_value));
}
std::string
GenerateRandomString
(
size_t
length) {
std::string letters =
"
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
"
;
std::random_device device;
std::mt19937
generator
(
device
());
std::uniform_int_distribution<
unsigned
int
>
dis
(
0u
, letters.
length
() -
1
);
std::string result;
result.
resize
(length);
for
(
auto
i =
0u
; i < length; ++i) {
result[i] += letters[
dis
(generator)];
}
return
result;
}
void
FillSubQuads
(std::
int32_t
depth, std::vector<std::
uint16_t
>& sub_quads_) {
const
auto
sub_tile =
olp::geo::TileKey::FromRowColumnLevel
(
0
,
0
, depth);
const
auto
start_level_id = sub_tile.
ToQuadKey64
();
const
auto
tiles_count =
olp::geo::QuadKey64Helper::ChildrenAtLevel
(depth);
std::vector<std::
uint64_t
>
layer_ids
(tiles_count);
std::iota
(layer_ids.
begin
(), layer_ids.
end
(), start_level_id);
sub_quads_.
insert
(sub_quads_.
end
(), layer_ids.
begin
(), layer_ids.
end
());
}
mockserver::TileMetadata
MakePartition
(
std::string data_handle, olp::porting::optional<
int32_t
> version) {
mockserver::TileMetadata partition;
partition.
data_handle
=
std::move
(data_handle);
partition.
version
= version;
partition.
crc
=
GenerateRandomString
(
6
);
partition.
checksum
=
GenerateRandomString
(
32
);
partition.
data_size
=
100
;
partition.
compressed_data_size
=
10
;
return
partition;
}
}
//
namespace
namespace
mockserver
{
std::string
ReadDefaultResponses::GenerateData
(
size_t
length) {
return
GenerateRandomString
(length);
}
std::string
ReadDefaultResponses::GenerateQuadTreeResponse
(
olp::geo::TileKey root_tile, std::
uint32_t
depth,
const
std::vector<std::
uint32_t
>& available_levels) {
std::map<std::
uint64_t
, TileMetadata> sub_quads;
std::map<std::
uint64_t
, TileMetadata> parent_quads;
//
generate data
for
(
auto
level : available_levels) {
if
(level < root_tile.
Level
()) {
auto
key = root_tile.
ChangedLevelTo
(level).
ToQuadKey64
();
parent_quads[key] =
MakePartition
(
GenerateDataHandle
(
std::to_string
(key)),
0
);
}
else
{
const
auto
level_depth = level - root_tile.
Level
();
if
(level_depth > depth) {
continue
;
}
std::vector<std::
uint16_t
> sub_quads_vector;
FillSubQuads
(level_depth, sub_quads_vector);
for
(
const
auto
& sub_quad : sub_quads_vector) {
const
auto
partition = root_tile.
AddedSubkey64
(sub_quad).
ToHereTile
();
sub_quads[sub_quad] =
MakePartition
(
GenerateDataHandle
(partition),
0
);
}
}
}
boost::json::object doc;
WriteSubquadsToJson
(doc, root_tile, sub_quads);
WriteParentquadsToJson
(doc, parent_quads);
return
boost::json::serialize
(doc);
}
QuadTreeBuilder::QuadTreeBuilder
(olp::geo::TileKey root_tile,
olp::porting::optional<
int32_t
> version)
: root_tile_(root_tile), base_version_(version) {}
QuadTreeBuilder&
QuadTreeBuilder::WithParent
(
olp::geo::TileKey parent, std::string data_handle,
olp::porting::optional<
int32_t
> version) {
assert
(root_tile_.
IsChildOf
(parent));
//
Make sure to set version when the base_version is set
if
(version != olp::porting::none) {
assert
(base_version_ != olp::porting::none);
}
else
if
(base_version_) {
version = base_version_;
}
parent_quads_[parent.
ToQuadKey64
()] =
MakePartition
(
std::move
(data_handle), version);
return
*
this
;
}
QuadTreeBuilder&
QuadTreeBuilder::FillParents
() {
auto
key = root_tile_.
Parent
();
while
(key.
IsValid
()) {
auto
quad_key = key.
ToQuadKey64
();
if
(parent_quads_.
find
(quad_key) == parent_quads_.
end
()) {
parent_quads_[quad_key] =
MakePartition
(
GenerateRandomString
(
32
), base_version_);
}
}
return
*
this
;
}
QuadTreeBuilder&
QuadTreeBuilder::WithSubQuad
(
olp::geo::TileKey tile, std::string datahandle,
olp::porting::optional<
int32_t
> version) {
assert
(tile.
IsChildOf
(root_tile_) || tile == root_tile_);
assert
((tile.
Level
() - root_tile_.
Level
()) <=
4
);
if
(version != olp::porting::none) {
assert
(base_version_ != olp::porting::none);
}
auto
origin = root_tile_.
ChangedLevelTo
(tile.
Level
());
auto
sub_quad =
olp::geo::TileKey::FromRowColumnLevel
(tile.
Row
() - origin.
Row
(),
tile.
Column
() - origin.
Column
(),
tile.
Level
() - root_tile_.
Level
())
.
ToQuadKey64
();
sub_quads_[sub_quad] =
MakePartition
(
std::move
(datahandle), version);
return
*
this
;
}
std::string
QuadTreeBuilder::BuildJson
()
const
{
boost::json::object doc;
WriteSubquadsToJson
(doc, root_tile_, sub_quads_);
WriteParentquadsToJson
(doc, parent_quads_);
return
boost::json::serialize
(doc);
}
olp::geo::TileKey
QuadTreeBuilder::Root
()
const
{
return
root_tile_; }
}
//
namespace mockserver
Back
|
FazBrowse Home
|
New Git URL