Skip to content

Commit f3b9030

Browse files
committed
Fix issues
Signed-off-by: JCW <[email protected]>
1 parent d208e19 commit f3b9030

File tree

3 files changed

+59
-23
lines changed

3 files changed

+59
-23
lines changed

include/xrpl/beast/utility/Journal.h

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ operator<<(std::ostream& os, LogParameter<T> const& param);
7979

8080
namespace beast {
8181

82+
// Forward declaration for use in interfaces
83+
namespace detail {
84+
class SimpleJsonWriter;
85+
}
86+
87+
// Type alias for journal attribute factory functions
88+
using JournalAttributesFactory = void(detail::SimpleJsonWriter&);
89+
90+
namespace detail {
91+
8292
class SimpleJsonWriter
8393
{
8494
public:
@@ -125,6 +135,16 @@ class SimpleJsonWriter
125135
stream_.append("\","sv);
126136
}
127137
std::string_view
138+
writeInt(std::int8_t val) const
139+
{
140+
return pushNumber(val, stream_);
141+
}
142+
std::string_view
143+
writeInt(std::int16_t val) const
144+
{
145+
return pushNumber(val, stream_);
146+
}
147+
std::string_view
128148
writeInt(std::int32_t val) const
129149
{
130150
return pushNumber(val, stream_);
@@ -135,6 +155,21 @@ class SimpleJsonWriter
135155
return pushNumber(val, stream_);
136156
}
137157
std::string_view
158+
writeUInt(std::size_t val) const
159+
{
160+
return pushNumber(val, stream_);
161+
}
162+
std::string_view
163+
writeUInt(std::uint8_t val) const
164+
{
165+
return pushNumber(val, stream_);
166+
}
167+
std::string_view
168+
writeUInt(std::uint16_t val) const
169+
{
170+
return pushNumber(val, stream_);
171+
}
172+
std::string_view
138173
writeUInt(std::uint32_t val) const
139174
{
140175
return pushNumber(val, stream_);
@@ -259,6 +294,8 @@ class SimpleJsonWriter
259294
std::string& stream_;
260295
};
261296

297+
} // namespace detail
298+
262299
/** A namespace for easy access to logging severity values. */
263300
namespace severities {
264301
/** Severity level / threshold of a Journal message. */
@@ -312,15 +349,15 @@ class Journal
312349
class JsonLogContext
313350
{
314351
std::string buffer_;
315-
SimpleJsonWriter messageParamsWriter_;
352+
detail::SimpleJsonWriter messageParamsWriter_;
316353

317354
public:
318355
JsonLogContext() : messageParamsWriter_(buffer_)
319356
{
320357
buffer_.reserve(1024 * 5);
321358
}
322359

323-
SimpleJsonWriter&
360+
detail::SimpleJsonWriter&
324361
writer()
325362
{
326363
return messageParamsWriter_;
@@ -596,7 +633,7 @@ class Journal
596633
: m_name(other.m_name), m_sink(other.m_sink)
597634
{
598635
std::string stream{other.m_attributesJson};
599-
SimpleJsonWriter writer{stream};
636+
detail::SimpleJsonWriter writer{stream};
600637
if (other.m_attributesJson.empty())
601638
{
602639
writer.startObject();
@@ -620,7 +657,7 @@ class Journal
620657
: m_name(name), m_sink(&sink)
621658
{
622659
std::string stream;
623-
SimpleJsonWriter writer{stream};
660+
detail::SimpleJsonWriter writer{stream};
624661
writer.startObject();
625662
attributesFactory(writer);
626663
m_attributesJson = std::move(stream);
@@ -741,7 +778,7 @@ class Journal
741778

742779
auto isEmpty = globalLogAttributesJson_.empty();
743780
std::string stream{std::move(globalLogAttributesJson_)};
744-
SimpleJsonWriter writer{stream};
781+
detail::SimpleJsonWriter writer{stream};
745782
if (isEmpty)
746783
{
747784
writer.startObject();
@@ -860,7 +897,7 @@ namespace ripple::log {
860897
namespace detail {
861898

862899
template <typename T>
863-
concept CanToChars = requires(T val) {
900+
concept ToCharsFormattable = requires(T val) {
864901
{
865902
to_chars(std::declval<char*>(), std::declval<char*>(), val)
866903
} -> std::convertible_to<std::to_chars_result>;
@@ -869,14 +906,22 @@ concept CanToChars = requires(T val) {
869906
template <typename T>
870907
void
871908
setJsonValue(
872-
beast::SimpleJsonWriter& writer,
909+
beast::detail::SimpleJsonWriter& writer,
873910
char const* name,
874911
T&& value,
875912
std::ostream* outStream)
876913
{
877914
using ValueType = std::decay_t<T>;
878915
writer.writeKey(name);
879-
if constexpr (std::is_integral_v<ValueType>)
916+
if constexpr (std::is_same_v<ValueType, bool>)
917+
{
918+
auto sv = writer.writeBool(value);
919+
if (outStream)
920+
{
921+
outStream->write(sv.data(), sv.size());
922+
}
923+
}
924+
else if constexpr (std::is_integral_v<ValueType>)
880925
{
881926
std::string_view sv;
882927
if constexpr (std::is_signed_v<ValueType>)
@@ -901,14 +946,6 @@ setJsonValue(
901946
outStream->write(sv.data(), sv.size());
902947
}
903948
}
904-
else if constexpr (std::is_same_v<ValueType, bool>)
905-
{
906-
auto sv = writer.writeBool(value);
907-
if (outStream)
908-
{
909-
outStream->write(sv.data(), sv.size());
910-
}
911-
}
912949
else if constexpr (
913950
std::is_same_v<ValueType, char const*> ||
914951
std::is_same_v<ValueType, char*>)
@@ -929,15 +966,14 @@ setJsonValue(
929966
}
930967
else
931968
{
932-
if constexpr (CanToChars<ValueType>)
969+
if constexpr (ToCharsFormattable<ValueType>)
933970
{
934971
char buffer[1024];
935972
std::to_chars_result result =
936973
to_chars(std::begin(buffer), std::end(buffer), value);
937974
if (result.ec == std::errc{})
938975
{
939-
std::string_view sv;
940-
sv = {std::begin(buffer), result.ptr};
976+
std::string_view sv{std::begin(buffer), result.ptr};
941977
writer.writeString(sv);
942978
if (outStream)
943979
{
@@ -1010,7 +1046,7 @@ template <typename... Pair>
10101046
[[nodiscard]] auto
10111047
attributes(Pair&&... pairs)
10121048
{
1013-
return [&](beast::SimpleJsonWriter& writer) {
1049+
return [&](beast::detail::SimpleJsonWriter& writer) {
10141050
(detail::setJsonValue(writer, pairs.first, pairs.second, nullptr), ...);
10151051
};
10161052
}

src/xrpld/app/main/Application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ class ApplicationImp : public Application, public BasicApp
834834
beast::Journal
835835
journal(
836836
std::string const& name,
837-
std::function<void(beast::SimpleJsonWriter&)> const& attributes)
837+
std::function<beast::JournalAttributesFactory> const& attributes)
838838
override;
839839

840840
beast::Journal
@@ -2178,7 +2178,7 @@ ApplicationImp::serverOkay(std::string& reason)
21782178
beast::Journal
21792179
ApplicationImp::journal(
21802180
std::string const& name,
2181-
std::function<void(beast::SimpleJsonWriter&)> const& attributes)
2181+
std::function<beast::JournalAttributesFactory> const& attributes)
21822182
{
21832183
return logs_->journal(name, std::move(attributes));
21842184
}

src/xrpld/app/main/Application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class Application : public beast::PropertyStream::Source
260260
virtual beast::Journal
261261
journal(
262262
std::string const& name,
263-
std::function<void(beast::SimpleJsonWriter&)> const& attributes) = 0;
263+
std::function<beast::JournalAttributesFactory> const& attributes) = 0;
264264

265265
virtual beast::Journal
266266
journal(std::string const& name) = 0;

0 commit comments

Comments
 (0)