Skip to content

Commit 3f2bf8a

Browse files
committed
Make json_t embeddable in value_t (copied).
1 parent df7dd93 commit 3f2bf8a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/bitcoin/network/messages/rpc/model.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ struct value_t
7474

7575
/// type-erased shared_ptr<Type>, not json deserializable.
7676
/// Pass ptr via any_t and specify it directly in the handler.
77-
any_t
77+
any_t,
78+
79+
/// Embeds json DOM.
80+
json_t
7881
>;
7982

8083
/// Explicit initialization constructors.
@@ -96,6 +99,8 @@ struct value_t
9699
value_t(uint16_t value) NOEXCEPT : inner_{ value } {}
97100
value_t(uint32_t value) NOEXCEPT : inner_{ value } {}
98101
value_t(uint64_t value) NOEXCEPT : inner_{ value } {}
102+
value_t(const json_t& value) NOEXCEPT : inner_{ value } {}
103+
value_t(json_t&& value) NOEXCEPT : inner_{ std::move(value) } {}
99104
value_t(const any_t& value) NOEXCEPT : inner_{ value } {}
100105
value_t(any_t&& value) NOEXCEPT : inner_{ std::move(value) } {}
101106

@@ -115,6 +120,7 @@ struct value_t
115120
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, uint16_t, inner_)
116121
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, uint32_t, inner_)
117122
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, uint64_t, inner_)
123+
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, json_t, inner_)
118124
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, any_t, inner_)
119125

120126
inner_t& value() NOEXCEPT

src/messages/rpc/model.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ DEFINE_JSON_FROM_TAG(value_t)
112112
{
113113
value = visit;
114114
},
115+
[&](const json_t& visit) NOEXCEPT
116+
{
117+
// This is a deep copy.
118+
value = visit;
119+
},
115120
[&](const array_t& visit) THROWS
116121
{
117122
value.emplace_array();

0 commit comments

Comments
 (0)