diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-04-08 17:57:22 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2018-04-08 18:13:49 +0200 |
commit | 97785863e2faa4a6d4e1130e300011985df0858c (patch) | |
tree | 786d40d6722e49fa007387719f113a07601a5b20 /src/netaddress.h | |
parent | 15c3bb4268f3366c26a1ba28d32216f2ff86fe7f (diff) | |
parent | 9272d70536287d4ff9aa1ee41a401465c0e8194a (diff) |
Merge #12886: Introduce Span type and use it instead of FLATDATA
9272d70 Support serializing Span<unsigned char> and use that instead of FLATDATA (Pieter Wuille)
833bc08 Add Slice: a (pointer, size) array view that acts like a container (Pieter Wuille)
Pull request description:
Introduce a new data type `Span`, which is an encapsulated pointer + size (like C++20's `std::span` or LevelDB's `Slice`), and represents a view to a sequence of objects laid out continuously in memory.
The immediate use case is replacing the remaining `FLATDATA` invocations. Instead of those, we support serializing/deserializing unsigned char `Span`s (treating them as arrays).
A longer term goal for `Span`s is making the script execution operate on them rather than on `CScript` itself. This will allow separate storage mechanisms for scripts.
Tree-SHA512: 7b0da3c802e5df367f223275004d16b04262804c007b7c73fda927176f0a9c3b2ef3225fa842cb73500b0df73175ec1419f1f5239de2402e21dd9ae8e5d05233
Diffstat (limited to 'src/netaddress.h')
-rw-r--r-- | src/netaddress.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/netaddress.h b/src/netaddress.h index ad6b55eb58..b3d1407f72 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -11,6 +11,7 @@ #include <compat.h> #include <serialize.h> +#include <span.h> #include <stdint.h> #include <string> @@ -167,10 +168,13 @@ class CService : public CNetAddr template <typename Stream, typename Operation> inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(ip); + + // TODO: introduce native support for BE serialization in serialize.h unsigned short portN = htons(port); - READWRITE(FLATDATA(portN)); - if (ser_action.ForRead()) + READWRITE(Span<unsigned char>((unsigned char*)&portN, 2)); + if (ser_action.ForRead()) { port = ntohs(portN); + } } }; |