Skip to content

Commit 5e5c8f8

Browse files
committed
serialize: add SER_PARAMS_OPFUNC
1 parent 33203f5 commit 5e5c8f8

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/netaddress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class CNetAddr
218218
};
219219
struct SerParams {
220220
const Encoding enc;
221+
SER_PARAMS_OPFUNC
221222
};
222223
static constexpr SerParams V1{Encoding::V1};
223224
static constexpr SerParams V2{Encoding::V2};

src/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ class CAddress : public CService
396396
};
397397
struct SerParams : CNetAddr::SerParams {
398398
const Format fmt;
399+
SER_PARAMS_OPFUNC
399400
};
400401
static constexpr SerParams V1_NETWORK{{CNetAddr::Encoding::V1}, Format::Network};
401402
static constexpr SerParams V2_NETWORK{{CNetAddr::Encoding::V2}, Format::Network};

src/serialize.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,4 +1192,17 @@ static auto WithParams(const Params& params, T&& t)
11921192
return ParamsWrapper<Params, T>{params, t};
11931193
}
11941194

1195+
/**
1196+
* Helper macro for SerParams structs
1197+
*
1198+
* Allows you define SerParams instances and then apply them directly
1199+
* to an object via function call syntax, eg:
1200+
*
1201+
* constexpr SerParams FOO{....};
1202+
* ss << FOO(obj);
1203+
*/
1204+
#define SER_PARAMS_OPFUNC \
1205+
template <typename T> \
1206+
auto operator()(T&& t) const { return WithParams(*this, t); }
1207+
11951208
#endif // BITCOIN_SERIALIZE_H

0 commit comments

Comments
 (0)