Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary fix for TimeSyncMessage invalid json serialization #563

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/v2i-hub/CARMAStreetsPlugin/src/CARMAStreetsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@ void CARMAStreetsPlugin::OnConfigChanged(const char *key, const char *value) {
void CARMAStreetsPlugin::HandleTimeSyncMessage(tmx::messages::TimeSyncMessage &msg, routeable_message &routeableMsg ) {
PluginClientClockAware::HandleTimeSyncMessage(msg, routeableMsg);
if ( isSimulationMode()) {
PLOG(logINFO) << "Handling TimeSync messages!" << std::endl;
produce_kafka_msg(msg.to_string(), "time_sync");
// TODO: This is a temporary fix for tmx message container property tree
// serializing all attributes as strings. This issue needs to be fixed but
// is currently out of scope. TMX Messages should be correctly serialize to
// and from json. This temporary fix simply using regex to look for numeric,
// null, and bool values and removes the quotations around them.
boost::regex exp("\"(null|true|false|[0-9]+(\\.[0-9]+)?)\"");
Copy link
Collaborator

@willjohnsonk willjohnsonk Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just a quick fix, but could this potentially cast numeric-only hex values differently than those with letters? If that is how they're passed via json in the existing code at least. Not sure if many, if any, fields will be affected either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this is only being called on a single message, the TimeSyncMessage with two attributes seq and timestep, both are numeric. I do not think we need any protection against hex strings represented in json here.

std::stringstream ss;
std::string rv = boost::regex_replace(msg.to_string(), exp, "$1");
PLOG(logINFO) << "Sending Time Sync Message " << rv << std::endl;

produce_kafka_msg(rv, "time_sync");
}
}
void CARMAStreetsPlugin::HandleMobilityOperationMessage(tsm3Message &msg, routeable_message &routeableMsg ) {
Expand Down
Loading