Skip to content

Commit b9e6cef

Browse files
Enable SAX parser to handle compressedDataSize
Parser was not expecting compressedDataSize field and failed to parse the JSON. Relates-To: OCMAM-223 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 068929d commit b9e6cef

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023-2024 HERE Europe B.V.
2+
* Copyright (C) 2023-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,11 +79,13 @@ bool PartitionsSaxHandler::String(const char* str, unsigned int length, bool) {
7979
case State::kParsingIgnoreAttribute:
8080
break;
8181

82-
case State::kWaitForRootObject: // Not expected
83-
case State::kWaitForNextPartition: // Not expected
84-
case State::kWaitForRootObjectEnd: // Not expected
85-
case State::kParsingVersion: // Version is not a string
86-
case State::kParsingDataSize: // DataSize is not a string
82+
case State::kWaitForRootObject: // Not expected
83+
case State::kWaitForNextPartition: // Not expected
84+
case State::kWaitForRootObjectEnd: // Not expected
85+
case State::kParsingVersion: // Version is not a string
86+
case State::kParsingDataSize: // DataSize is not a string
87+
case State::kParsingCompressedDataSize: // CompressedDataSize is not a
88+
// string
8789
default:
8890
return false;
8991
}
@@ -98,6 +100,8 @@ bool PartitionsSaxHandler::Uint(unsigned int value) {
98100
partition_.SetVersion(value);
99101
} else if (state_ == State::kParsingDataSize) {
100102
partition_.SetDataSize(value);
103+
} else if (state_ == State::kParsingCompressedDataSize) {
104+
partition_.SetCompressedDataSize(value);
101105
} else {
102106
return false;
103107
}
@@ -162,6 +166,8 @@ PartitionsSaxHandler::State PartitionsSaxHandler::ProcessNextAttribute(
162166
return State::kParsingChecksum;
163167
case HashStringToInt("dataSize"):
164168
return State::kParsingDataSize;
169+
case HashStringToInt("compressedDataSize"):
170+
return State::kParsingCompressedDataSize;
165171
case HashStringToInt("version"):
166172
return State::kParsingVersion;
167173
case HashStringToInt("crc"):

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 HERE Europe B.V.
2+
* Copyright (C) 2023-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,6 +70,7 @@ class PartitionsSaxHandler
7070
kParsingDataHandle,
7171
kParsingChecksum,
7272
kParsingDataSize,
73+
kParsingCompressedDataSize,
7374
kParsingCrc,
7475
kParsingIgnoreAttribute,
7576

olp-cpp-sdk-dataservice-read/tests/PartitionsSaxHandlerTest.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 HERE Europe B.V.
2+
* Copyright (C) 2023-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ const char* kDataHandle = "dataHandle";
3232
const char* kPartition = "partition";
3333
const char* kChecksum = "checksum";
3434
const char* kDataSize = "dataSize";
35+
const char* kCompressedDataSize = "compressedDataSize";
3536
const char* kVersion = "version";
3637
const char* kCrc = "crc";
3738

@@ -65,6 +66,8 @@ TEST(PartitionsSaxHandlerTest, NormalFlow) {
6566
ASSERT_TRUE(handler.String(kChecksumValue, len(kChecksumValue), true));
6667
ASSERT_TRUE(handler.String(kDataSize, len(kDataSize), true));
6768
ASSERT_TRUE(handler.Uint(150));
69+
ASSERT_TRUE(handler.String(kCompressedDataSize, len(kCompressedDataSize), true));
70+
ASSERT_TRUE(handler.Uint(100));
6871
ASSERT_TRUE(handler.String(kVersion, len(kVersion), true));
6972
ASSERT_TRUE(handler.Uint(6));
7073
ASSERT_TRUE(handler.String(kCrc, len(kCrc), true));
@@ -80,6 +83,7 @@ TEST(PartitionsSaxHandlerTest, NormalFlow) {
8083
std::string(kChecksumValue));
8184
EXPECT_EQ(parsed_partition.GetCrc().get_value_or(""), std::string(kCrcValue));
8285
EXPECT_EQ(parsed_partition.GetDataSize().get_value_or(0), 150);
86+
EXPECT_EQ(parsed_partition.GetCompressedDataSize().get_value_or(0), 100);
8387
EXPECT_EQ(parsed_partition.GetVersion().get_value_or(0), 6);
8488
}
8589

0 commit comments

Comments
 (0)