@@ -116,26 +116,24 @@ static constexpr uint8_t PSBT_OUT_BIP32_DERIVATION = 0x02;
116
116
// as a 0 length key which indicates that this is the separator. The separator has no value.
117
117
static constexpr uint8_t PSBT_SEPARATOR = 0x00 ;
118
118
119
- // Takes a stream and multiple arguments and serializes them into a vector and then into the stream
119
+ // Takes a stream and multiple arguments and serializes them as if first serialized into a vector and then into the stream
120
120
// The resulting output into the stream has the total serialized length of all of the objects followed by all objects concatenated with each other.
121
121
template <typename Stream, typename ... X>
122
122
void SerializeToVector (Stream& s, const X&... args)
123
123
{
124
- std::vector<unsigned char > ret;
125
- CVectorWriter ss (SER_NETWORK, PROTOCOL_VERSION, ret, 0 );
126
- SerializeMany (ss, args...);
127
- s << ret;
124
+ WriteCompactSize (s, GetSerializeSizeMany (s, args...));
125
+ SerializeMany (s, args...);
128
126
}
129
127
130
128
// Takes a stream and multiple arguments and unserializes them first as a vector then each object individually in the order provided in the arguments
131
129
template <typename Stream, typename ... X>
132
130
void UnserializeFromVector (Stream& s, X&... args)
133
131
{
134
- std::vector< unsigned char > data ;
135
- s >> data ;
136
- CDataStream ss (data, SER_NETWORK, PROTOCOL_VERSION );
137
- UnserializeMany (ss, args... );
138
- if (!ss. eof () ) {
132
+ size_t expected_size = ReadCompactSize (s) ;
133
+ size_t remaining_before = s. size () ;
134
+ UnserializeMany (s, args... );
135
+ size_t remaining_after = s. size ( );
136
+ if (remaining_after + expected_size != remaining_before ) {
139
137
throw std::ios_base::failure (" Size of value was not the stated size" );
140
138
}
141
139
}
0 commit comments