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

json: minor clean-ups #17403

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/v/compat/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "cluster/errc.h"
#include "cluster/partition_balancer_types.h"
#include "cluster/types.h"
#include "container/json.h"
#include "json/document.h"
#include "json/json.h"
#include "model/fundamental.h"
Expand Down
29 changes: 29 additions & 0 deletions src/v/container/include/container/json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 Redpanda Data, Inc.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.md
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0
*/
#pragma once

#include "container/fragmented_vector.h"
#include "json/json.h"

namespace json {

template<typename T, size_t max_fragment_size>
void rjson_serialize(
json::Writer<json::StringBuffer>& w,
const fragmented_vector<T, max_fragment_size>& v) {
w.StartArray();
for (const auto& e : v) {
rjson_serialize(w, e);
}
w.EndArray();
}

} // namespace json
12 changes: 0 additions & 12 deletions src/v/json/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#pragma once

#include "container/fragmented_vector.h"
#include "json/_include_first.h"
#include "json/prettywriter.h"
#include "json/reader.h"
Expand Down Expand Up @@ -95,17 +94,6 @@ void rjson_serialize(
w.EndArray();
}

template<typename T, size_t max_fragment_size>
void rjson_serialize(
json::Writer<json::StringBuffer>& w,
const fragmented_vector<T, max_fragment_size>& v) {
w.StartArray();
for (const auto& e : v) {
rjson_serialize(w, e);
}
w.EndArray();
}

template<typename T, size_t chunk_size = 128>
void rjson_serialize(
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need to fix these other functions too?

Copy link
Contributor

Choose a reason for hiding this comment

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

By fix I mean move to the public header? The public header is re-exporting these methods right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry i'm not sure what you mean. what's an example?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I was confused that the new json.h file is in container/include/container, originally I thought you put that in json/include/json. I am assuming that moving json serialization to the container module is intentional? Should we be doing that for everything? Or maybe we should be doing the serde approach and just have a template version?

I am assuming you're moving rjson_serialize for fragmented_vector for some cyclical dependency?

Copy link
Member Author

@dotnwat dotnwat Mar 27, 2024

Choose a reason for hiding this comment

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

Yeh, definitely open to alternatives here. The idea is that it is not scalable for json/json.h to have overrides for everything (e.g. container/* net/*, etc...) and that each module should have its own json.h for its types. what remains in json/json.h would be overloads for external dependencies and stuff in base/*.

wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

That SGTM

json::Writer<json::StringBuffer>& w,
Expand Down