veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
altintegration::WriteStream Class Reference

Binary writer that is useful for binary serialization. More...

Detailed Description

Definition at line 20 of file write_stream.hpp.

#include <write_stream.hpp>

+ Collaboration diagram for altintegration::WriteStream:

Public Types

using storage_t = std::vector< uint8_t >
 

Public Member Functions

 WriteStream (size_t size)
 
 WriteStream (WriteStream &&)=default
 
WriteStreamoperator= (WriteStream &&)=default
 
void write (const void *buf, size_t size)
 
template<typename T , typename = typename std::enable_if<sizeof(typename T::value_type) == 1>::type>
void write (const T &t)
 
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
void writeBE (T num, size_t bytes=sizeof(T))
 
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
void writeLE (T num)
 
uint32_t getVersion () const noexcept
 
void setVersion (uint32_t version) noexcept
 
const storage_t & data () const noexcept
 
std::string hex () const noexcept
 

Member Typedef Documentation

◆ storage_t

using altintegration::WriteStream::storage_t = std::vector<uint8_t>

Definition at line 24 of file write_stream.hpp.

Member Function Documentation

◆ write()

template<typename T , typename = typename std::enable_if<sizeof(typename T::value_type) == 1>::type>
void altintegration::WriteStream::write ( const T &  t)
inline

Definition at line 37 of file write_stream.hpp.

37 {
38 write(t.data(), t.size());
39 }

◆ writeBE()

template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
void altintegration::WriteStream::writeBE ( num,
size_t  bytes = sizeof(T) 
)
inline

Definition at line 44 of file write_stream.hpp.

44 {
45 VBK_ASSERT(bytes <= sizeof(T));
46
47 for (size_t i = 0, shift = (sizeof(T) - 1) * 8; i < sizeof(T);
48 i++, shift -= 8) {
49 // skip first bytes
50 if (i < (sizeof(T) - bytes)) {
51 continue;
52 }
53 m_data.push_back((num >> shift) & 0xffu);
54 }
55 }

◆ writeLE()

template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
void altintegration::WriteStream::writeLE ( num)
inline

Definition at line 60 of file write_stream.hpp.

60 {
61 for (size_t i = 0, shift = 0; i < sizeof(T); i++, shift += 8) {
62 m_data.push_back((num >> shift) & 0xffu);
63 }
64 }

The documentation for this class was generated from the following file: