Skip to content

Commit 8db6061

Browse files
Updated measurement key implementations to be based on uint64 id values and enhanced ParseMeasurementKey to resolve measurement keys that were only numeric.
1 parent 530af78 commit 8db6061

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

src/lib/Convert.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ bool sttp::TryParseInt64(const string& value, int64_t& result, const int64_t def
384384
}
385385
}
386386

387+
bool sttp::TryParseUInt64(const string& value, uint64_t& result, const uint64_t defaultValue)
388+
{
389+
try
390+
{
391+
result = stoull(value);
392+
return true;
393+
}
394+
catch (...)
395+
{
396+
result = defaultValue;
397+
return false;
398+
}
399+
}
400+
387401
bool sttp::TryParseDouble(const string& value, float64_t& result, const float64_t defaultValue)
388402
{
389403
try

src/lib/Convert.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ namespace sttp
9090
bool TryParseInt32(const std::string& value, int32_t& result, int32_t defaultValue = 0);
9191

9292
bool TryParseInt64(const std::string& value, int64_t& result, int64_t defaultValue = 0LL);
93+
94+
bool TryParseUInt64(const std::string& value, uint64_t& result, uint64_t defaultValue = 0ULL);
9395

9496
bool TryParseDouble(const std::string& value, float64_t& result, float64_t defaultValue = 0.0);
9597

src/lib/transport/SubscriberConnection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,10 +1114,10 @@ SignalIndexCachePtr SubscriberConnection::ParseSubscriptionRequest(const string&
11141114
const DataRowPtr& row = rows[i];
11151115
const Guid& signalID = row->ValueAsGuid(signalIDColumn).GetValueOrDefault();
11161116
string source;
1117-
uint32_t id;
1117+
uint64_t id;
11181118

11191119
ParseMeasurementKey(row->ValueAsString(idColumn).GetValueOrDefault(), source, id);
1120-
signalIndexCache->AddMeasurementKey(uint16_t(i), signalID, source, id, charSizeEstimate);
1120+
signalIndexCache->AddMeasurementKey(int32_t(i), signalID, source, id, charSizeEstimate);
11211121
}
11221122

11231123
success = true;

src/lib/transport/TransportTypes.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,42 @@ std::string sttp::transport::GetProtocolType(const std::string& protocolName)
268268
return "Frame";
269269
}
270270

271-
void sttp::transport::ParseMeasurementKey(const std::string& key, std::string& source, uint32_t& id)
271+
void sttp::transport::ParseMeasurementKey(const std::string& key, std::string& source, uint64_t& id)
272272
{
273273
const vector<string> parts = Split(key, ":");
274+
const size_t length = parts.size();
274275

275-
if (parts.size() == 2)
276+
if (length == 2)
276277
{
277-
source = parts[0];
278-
id = uint32_t(stoul(parts[1]));
278+
source = parts[0];
279+
id = uint64_t(stoull(parts[1]));
280+
}
281+
else if (length > 2)
282+
{
283+
stringstream sourceParts;
284+
285+
for (size_t i = 0; i < length - 1; i++)
286+
{
287+
if (i > 0)
288+
sourceParts << ':';
289+
290+
sourceParts << source;
291+
}
292+
293+
source = sourceParts.str();
294+
id = uint64_t(stoull(parts[length - 1]));
279295
}
280296
else
281297
{
282-
source = parts[0];
283-
id = UInt32::MaxValue;
298+
if (TryParseUInt64(key, id))
299+
{
300+
source = Empty::String;
301+
}
302+
else
303+
{
304+
source = key;
305+
id = UInt64::MaxValue;
306+
}
284307
}
285308
}
286309

src/lib/transport/TransportTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ namespace transport
154154
std::string GetProtocolType(const std::string& protocolName);
155155

156156
// Parses a measurement key in the format of "Source:ID" into its parts
157-
void ParseMeasurementKey(const std::string& key, std::string& source, uint32_t& id);
157+
void ParseMeasurementKey(const std::string& key, std::string& source, uint64_t& id);
158158

159159
// Helper function to parse signal kind
160160
SignalKind ParseSignalKind(const std::string& acronym);

0 commit comments

Comments
 (0)