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

Populate data_envelope with topic in json::decode() #443

Merged
merged 1 commit into from
Feb 22, 2025
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
10 changes: 8 additions & 2 deletions libbroker/broker/format/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ error decode(std::string_view str, variant& result) {
if (!val)
return error{ec::invalid_json};
auto obj = val->to_object();

std::string_view topic = topic::reserved;
if (auto maybe_topic = obj.value("topic"); maybe_topic.is_string())
topic = std::string_view{maybe_topic.to_string().data(),
maybe_topic.to_string().size()};

// Try to convert the JSON structure into our binary serialization format.
std::vector<std::byte> buf;
buf.reserve(512); // Allocate some memory to avoid small allocations.
Expand All @@ -64,8 +70,8 @@ error decode(std::string_view str, variant& result) {
// Turn the binary data into a data envelope. TTL and sender/receiver are
// not part of the JSON representation, so we use defaults values.
auto res = data_envelope::deserialize(endpoint_id::nil(), endpoint_id::nil(),
defaults::ttl, topic::reserved,
buf.data(), buf.size());
defaults::ttl, topic, buf.data(),
buf.size());
if (!res)
return res.error();
result = (*res)->value();
Expand Down
Loading