Skip to content

Commit

Permalink
compat: add json helpers for some types
Browse files Browse the repository at this point in the history
- cluster::non_replicable_topic
- cluster::topic_result
- model::topic_namespace
  • Loading branch information
andrwng committed Aug 4, 2022
1 parent 1c0d114 commit fee45de
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/v/compat/cluster_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,41 @@ inline void read_value(json::Value const& v, cluster::tx_errc& obj) {
obj = {v.GetInt()};
}

inline void rjson_serialize(
json::Writer<json::StringBuffer>& w, const cluster::non_replicable_topic& t) {
w.StartObject();
w.Key("source");
rjson_serialize(w, t.source);
w.Key("name");
rjson_serialize(w, t.name);
w.EndObject();
}

inline void
read_value(json::Value const& rd, cluster::non_replicable_topic& obj) {
model::topic_namespace source;
model::topic_namespace name;
read_member(rd, "source", source);
read_member(rd, "name", name);
obj = {.source = std::move(source), .name = std::move(name)};
}

inline void rjson_serialize(
json::Writer<json::StringBuffer>& w, const cluster::topic_result& t) {
w.StartObject();
w.Key("tp_ns");
rjson_serialize(w, t.tp_ns);
w.Key("ec");
rjson_serialize(w, t.ec);
w.EndObject();
}

inline void read_value(json::Value const& rd, cluster::topic_result& obj) {
model::topic_namespace tp_ns;
cluster::errc ec;
read_member(rd, "tp_ns", tp_ns);
read_member(rd, "ec", ec);
obj = cluster::topic_result(std::move(tp_ns), ec);
}

} // namespace json
18 changes: 18 additions & 0 deletions src/v/compat/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ inline void read_value(json::Value const& rd, model::broker& obj) {
std::move(properties));
}

inline void rjson_serialize(
json::Writer<json::StringBuffer>& w, const model::topic_namespace& t) {
w.StartObject();
w.Key("ns");
rjson_serialize(w, t.ns);
w.Key("tp");
rjson_serialize(w, t.tp);
w.EndObject();
}

inline void read_value(json::Value const& rd, model::topic_namespace& obj) {
model::ns ns;
model::topic tp;
read_member(rd, "ns", ns);
read_member(rd, "tp", tp);
obj = model::topic_namespace(std::move(ns), std::move(tp));
}

#define json_write(_fname) json::write_member(wr, #_fname, obj._fname)
#define json_read(_fname) json::read_member(rd, #_fname, obj._fname)

Expand Down

0 comments on commit fee45de

Please sign in to comment.