diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2023-11-22 14:47:00 -0500 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2024-01-11 06:51:57 -0500 |
commit | f3a2b5237688e9f574444e793724664b00fb7f2a (patch) | |
tree | e4937cc0e01e2bfedd0aac2cd1f14fa05c0d097c /src/primitives | |
parent | 4ae5171d42bd288cbd9a6f307e07b71067b184f5 (diff) |
serialization: Support for multiple parameters
This commit makes a minimal change to the ParamsStream class to let it retrieve
multiple parameters. Followup commits after this commit clean up code using
ParamsStream and make it easier to set multiple parameters.
Currently it is only possible to attach one serialization parameter to a stream
at a time. For example, it is not possible to set a parameter controlling the
transaction format and a parameter controlling the address format at the same
time because one parameter will override the other.
This limitation is inconvenient for multiprocess code since it is not possible
to create just one type of stream and serialize any object to it. Instead it is
necessary to create different streams for different object types, which
requires extra boilerplate and makes using the new parameter fields a lot more
awkward than the older version and type fields.
Fix this problem by allowing an unlimited number of serialization stream
parameters to be set, and allowing them to be requested by type. Later
parameters will still override earlier parameters, but only if they have the
same type.
This change requires replacing the stream.GetParams() method with a
stream.GetParams<T>() method in order for serialization code to retrieve the
desired parameters. This change is more verbose, but probably a good thing for
readability because previously it could be difficult to know what type the
GetParams() method would return, and now it is more obvious.
Diffstat (limited to 'src/primitives')
-rw-r--r-- | src/primitives/transaction.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index ccbeb3ec49..d15b8005f9 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -326,7 +326,7 @@ public: template <typename Stream> inline void Serialize(Stream& s) const { - SerializeTransaction(*this, s, s.GetParams()); + SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>()); } /** This deserializing constructor is provided instead of an Unserialize method. @@ -386,12 +386,12 @@ struct CMutableTransaction template <typename Stream> inline void Serialize(Stream& s) const { - SerializeTransaction(*this, s, s.GetParams()); + SerializeTransaction(*this, s, s.template GetParams<TransactionSerParams>()); } template <typename Stream> inline void Unserialize(Stream& s) { - UnserializeTransaction(*this, s, s.GetParams()); + UnserializeTransaction(*this, s, s.template GetParams<TransactionSerParams>()); } template <typename Stream> |