Double ended buffer combining vector and stream-like interfaces. * * >> and << read and write unformatted data using the above serialization templates. * Fills with data in linear time; some stringstream implementations take N^2 time. */
| 183 | * Fills with data in linear time; some stringstream implementations take N^2 time. |
| 184 | */ |
| 185 | class CDataStream |
| 186 | { |
| 187 | protected: |
| 188 | using vector_type = SerializeData; |
| 189 | vector_type vch; |
| 190 | vector_type::size_type m_read_pos{0}; |
| 191 | |
| 192 | int nType; |
| 193 | int nVersion; |
| 194 | |
| 195 | public: |
| 196 | typedef vector_type::allocator_type allocator_type; |
| 197 | typedef vector_type::size_type size_type; |
| 198 | typedef vector_type::difference_type difference_type; |
| 199 | typedef vector_type::reference reference; |
| 200 | typedef vector_type::const_reference const_reference; |
| 201 | typedef vector_type::value_type value_type; |
| 202 | typedef vector_type::iterator iterator; |
| 203 | typedef vector_type::const_iterator const_iterator; |
| 204 | typedef vector_type::reverse_iterator reverse_iterator; |
| 205 | |
| 206 | explicit CDataStream(int nTypeIn, int nVersionIn) |
| 207 | : nType{nTypeIn}, |
| 208 | nVersion{nVersionIn} {} |
| 209 | |
| 210 | explicit CDataStream(Span<const uint8_t> sp, int type, int version) : CDataStream{AsBytes(sp), type, version} {} |
| 211 | explicit CDataStream(Span<const value_type> sp, int nTypeIn, int nVersionIn) |
| 212 | : vch(sp.data(), sp.data() + sp.size()), |
| 213 | nType{nTypeIn}, |
| 214 | nVersion{nVersionIn} {} |
| 215 | |
| 216 | template <typename... Args> |
| 217 | CDataStream(int nTypeIn, int nVersionIn, Args&&... args) |
| 218 | : nType{nTypeIn}, |
| 219 | nVersion{nVersionIn} |
| 220 | { |
| 221 | ::SerializeMany(*this, std::forward<Args>(args)...); |
| 222 | } |
| 223 | |
| 224 | std::string str() const |
| 225 | { |
| 226 | return std::string{UCharCast(data()), UCharCast(data() + size())}; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | // |
| 231 | // Vector subset |
| 232 | // |
| 233 | const_iterator begin() const { return vch.begin() + m_read_pos; } |
| 234 | iterator begin() { return vch.begin() + m_read_pos; } |
| 235 | const_iterator end() const { return vch.end(); } |
| 236 | iterator end() { return vch.end(); } |
| 237 | size_type size() const { return vch.size() - m_read_pos; } |
| 238 | bool empty() const { return vch.size() == m_read_pos; } |
| 239 | void resize(size_type n, value_type c = value_type{}) { vch.resize(n + m_read_pos, c); } |
| 240 | void reserve(size_type n) { vch.reserve(n + m_read_pos); } |
| 241 | const_reference operator[](size_type pos) const { return vch[pos + m_read_pos]; } |
| 242 | reference operator[](size_type pos) { return vch[pos + m_read_pos]; } |
nothing calls this directly
no test coverage detected