|
| COutByteStreamBasic (size_t reserve=1024, bool net=kByteOrderDefault) |
| Constructor for COutByteStream/COutByteStreamStr, COutByteStreamVec. More...
|
|
| COutByteStreamBasic (buffer_type &buf, bool net=kByteOrderDefault) |
| Constructor for COutByteStreamStrRef, COutByteStreamVecRef. More...
|
|
| COutByteStreamBasic (char_type *buf, size_t sz, bool net=kByteOrderDefault) |
| Constructor for COutByteStreamBuf. More...
|
|
__Myt & | bad (int code) |
| Set status. More...
|
|
ssize_t | seek (size_t pos) |
| Set current pointer. More...
|
|
size_t | cur () const |
| Get current pointer. More...
|
|
size_t | size () const |
| Get byte size of data have been written, same as cur. More...
|
|
ssize_t | skip (ssize_t off) |
| Skip some bytes. More...
|
|
ssize_t | skip (ssize_t off, int fill) |
| Skip some bytes. More...
|
|
std::string | toString () const |
| Get a readable description of this object. More...
|
|
bool | finish () |
| Export data for COutByteStreamStrRef, COutByteStreamVecRef. More...
|
|
template<typename SizeT > |
bool | finish (SizeT *sz) |
| Export data for COutByteStreamBuf, COutByteStreamStrRef, COutByteStreamVecRef. More...
|
|
bool | finish (buffer_type &dst) |
| Export data for COutByteStream/COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef. More...
|
|
template<typename CharT > |
bool | finish (CharT *dst, size_t *sz) |
| Export data for COutByteStream/COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef, COutByteStreamBuf. More...
|
|
|
These functions write c to the underlying buffer, and extend it by sizeof c bytes, with appropriate byte order transformation.
- Parameters
-
- Returns
- Reference to self
|
__Myt & | operator<< (char c) |
|
__Myt & | operator<< (signed char c) |
|
__Myt & | operator<< (unsigned char c) |
|
__Myt & | operator<< (short c) |
|
__Myt & | operator<< (unsigned short c) |
|
__Myt & | operator<< (int c) |
|
__Myt & | operator<< (unsigned int c) |
|
__Myt & | operator<< (long c) |
|
__Myt & | operator<< (unsigned long c) |
|
__Myt & | operator<< (long long c) |
|
__Myt & | operator<< (unsigned long long c) |
|
__Myt & | operator<< (wchar_t c) |
|
|
__Myt & | operator<< (const std::string &c) |
| Pack a string. More...
|
|
__Myt & | operator<< (const std::wstring &c) |
| Pack a wide string. More...
|
|
template<class T , size_t N> |
__Myt & | operator<< (const T(&c)[N]) |
| Pack an array. More...
|
|
|
These functions operates on different manipulators to achieve special purpose.
Please see the corresponding manipulator generators in Manip for more information. - Parameters
-
- Returns
- Reference of self
|
template<class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorRawPtr< T > &m) |
|
template<class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorRawCont< T > &m) |
|
template<class ForwardIter > |
__Myt & | operator<< (const NS_IMPL::CManipulatorRawRange< ForwardIter > &m) |
|
template<typename LenT , class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorArrayPtr< LenT, T > &m) |
|
template<typename LenT , class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorArrayCont< LenT, T > &m) |
|
template<typename LenT , class ForwardIter > |
__Myt & | operator<< (const NS_IMPL::CManipulatorArrayRange< LenT, ForwardIter > &m) |
|
__Myt & | operator<< (void(*m)(__MyBase &)) |
|
template<class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorValueByteOrder< T > &m) |
|
__Myt & | operator<< (const NS_IMPL::CManipulatorSeek &m) |
|
__Myt & | operator<< (const NS_IMPL::CManipulatorSkip &m) |
|
__Myt & | operator<< (const NS_IMPL::CManipulatorSkipFill &m) |
|
template<typename T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorSkipPtr< T > &m) |
|
template<typename T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorSkipPtrFill< T > &m) |
|
template<class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorOffsetValue< T > &m) |
|
template<class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorInsert< T > &m) |
|
template<class T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorProtobuf< T > &m) |
|
template<typename T > |
__Myt & | operator<< (const NS_IMPL::CManipulatorVarint< T > &m) |
|
__Myt & | operator<< (const NS_IMPL::CManipulatorStubPush &m) |
|
__Myt & | operator<< (const NS_IMPL::CManipulatorStubPop &m) |
|
__Myt & | operator<< (const NS_IMPL::CManipulatorEnd< void, void > &m) |
|
__Myt & | operator<< (NS_IMPL::CManipulatorEnd< void, void >(*m)()) |
|
template<typename SizeT > |
__Myt & | operator<< (const NS_IMPL::CManipulatorEnd< SizeT *, void > &m) |
|
__Myt & | operator<< (const NS_IMPL::CManipulatorEnd< buffer_type, void > &m) |
|
template<typename CharT > |
__Myt & | operator<< (const NS_IMPL::CManipulatorEnd< CharT *, size_t * > &m) |
|
template<class Data>
class COutByteStreamBasic< Data >
Data packing interfaces.
COutByteStreamBasic is for easy data packing/encoding/serialization. It manages data endianness automatically, so you don't need to call hton/ntoh
family APIs manually. It also performs sufficient boundary checks so you won't end up with memory access violations.
COutByteStream supports a number of manipulators to operate on compound types and complex structures, which will make your code really concise and efficient.
The type of underlying byte buffer determines which variant of COutByteStreamBasic you may choose:
COutByteStream
(or COutByteStreamStr
) uses internal std::string
as the underlying byte buffer, which means you don't need to provide a byte buffer when constructing a COutByteStream
object, instead you could indicate a byte size to the internal std::string
object to reserve, so it might not need to expand (and copy data) later on.
In the contrary, COutByteStreamStrRef
needs an external std::string
object to store data, provided in the constructor. COutByteStreamStrRef
will hold a reference to the std::string
object and manipulate it during the process of serialization/encoding. New data will append to the std::string
object, so it's possible to deal with some legacy code and avoid performance loss.
- Internal
std::vector<char>
Similar to COutByteStream
, COutByteStreamVec
uses internal std::vector<char>
as the underlying buffer. You can treat them quite the same, and the purpose of COutByteStreamVec
is only for completion: some people prefer using std::vector<char>
as a buffer.
- External
std::vector<char>
COutByteStreamVecRef
needs an external std::vector<char>
object to construct, just like COutByteStreamStrRef
does. And every aspect is just the same for both of them, as described before.
COutByteStreamBuf
is different from all above. It receives a char
array as the underlying buffer, with fixed size, wrapped by CCharBuffer. It's impossible to expand the underlying buffer, and when it's full, all serialization operations will fail and status is set.
Here is an example use of COutByteStream:
uint32_t version;
string name;
vector<uint64_t> orders;
std::string buf;
out << version << name << Manip::array(orders)
Other variants are similar, except for the constructors and Manip::end part.
- Template Parameters
-
Data | Type of underlying byte buffer |
- Note
- COutByteStreamBasic is not intended for direct use, try variants introduced above.