Marine Library
1.0
C++ library for Linux Networking Development
|
Manipulators for stream interface APIs. More...
Functions | |
template<class T > | |
NS_IMPL::CManipulatorProtobuf< T > | protobuf (T &msg, size_t size=size_t(-1)) |
Pack/unpack Protocol Buffers messages. More... | |
template<typename T > | |
NS_IMPL::CManipulatorVarint< const T > | varint (const T &val) |
Pack integer using Base 128 Varints encoding. More... | |
template<typename T > | |
NS_IMPL::CManipulatorVarint< T > | varint (T &val) |
Unpack integer using Base 128 Varints encoding. More... | |
NS_IMPL::CManipulatorStubPush | stub (size_t sz) |
Set up a stub. More... | |
NS_IMPL::CManipulatorStubPop | stub_pop (bool align=false, bool check=false) |
Demolish the top most stub. More... | |
CToString & | boolalpha (CToString &tos) |
CToString & | noboolalpha (CToString &tos) |
NS_IMPL::CToStringWidth | setw (int w) |
NS_IMPL::CToStringFill | fill (char c) |
CToString & | left (CToString &tos) |
CToString & | right (CToString &tos) |
NS_IMPL::CToStringBase | setbase (int base) |
CToString & | dec (CToString &tos) |
CToString & | hex (CToString &tos) |
CToString & | oct (CToString &tos) |
CToString & | bin (CToString &tos) |
CToString & | showbase (CToString &tos) |
CToString & | noshowbase (CToString &tos) |
CToString & | autocase (CToString &tos) |
CToString & | uppercase (CToString &tos) |
CToString & | nouppercase (CToString &tos) |
CToString & | showpos (CToString &tos) |
CToString & | noshowpos (CToString &tos) |
CToString & | endl (CToString &tos) |
CToString & | ends (CToString &tos) |
Mapip::raw | |
Pack/unpack a range of elements, without leading size field.
| |
template<class T , size_t N> | |
NS_IMPL::CManipulatorRawPtr< T > | raw (T(&c)[N]) |
template<class T > | |
NS_IMPL::CManipulatorRawPtr< T > | raw (T *c, size_t sz) |
template<class T > | |
NS_IMPL::CManipulatorRawPtr< T > | raw (std::vector< T > &c, size_t sz) |
template<class T > | |
NS_IMPL::CManipulatorRawPtr< const T > | raw (const std::vector< T > &c, size_t *sz=NULL) |
template<typename Char > | |
NS_IMPL::CManipulatorRawPtr< Char > | raw (std::basic_string< Char > &c, size_t len) |
template<typename Char > | |
NS_IMPL::CManipulatorRawPtr< const Char > | raw (const std::basic_string< Char > &c, size_t *sz=NULL) |
template<class ForwardIter > | |
NS_IMPL::CManipulatorRawRange< ForwardIter > | raw (ForwardIter first, ForwardIter last, size_t *sz=NULL) |
template<class T > | |
NS_IMPL::CManipulatorRawCont< T > | raw (T &c, size_t sz) |
template<class T > | |
NS_IMPL::CManipulatorRawCont< const T > | raw (const T &c, size_t *sz=NULL) |
Mapip::array | |
Pack/unpack a range of elements, with leading size field.
| |
template<typename LenT , class T , size_t N> | |
NS_IMPL::CManipulatorArrayPtr< LenT, T > | array (T(&c)[N], LenT *real_sz) |
template<typename LenT , class T , size_t N> | |
NS_IMPL::CManipulatorArrayPtr< LenT, const T > | array (const T(&c)[N]) |
template<typename LenT , class T > | |
NS_IMPL::CManipulatorArrayPtr< LenT, T > | array (T *c, size_t sz, LenT *real_sz) |
template<typename LenT , class T > | |
NS_IMPL::CManipulatorArrayPtr< LenT, const T > | array (const T *c, size_t sz) |
template<typename LenT , class T > | |
NS_IMPL::CManipulatorArrayCont< LenT, T > | array (T &c, LenT max_size=0) |
template<typename LenT , class T > | |
NS_IMPL::CManipulatorArrayCont< LenT, const T > | array (const T &c) |
template<class T > | |
NS_IMPL::CManipulatorArrayCont< uint16_t, T > | array (T &c, uint16_t max_size=0) |
template<class T > | |
NS_IMPL::CManipulatorArrayCont< uint16_t, const T > | array (const T &c) |
template<typename LenT , class ForwardIter > | |
NS_IMPL::CManipulatorArrayRange< LenT, ForwardIter > | array (ForwardIter first, ForwardIter last, LenT *sz=NULL) |
Byte order | |
APIs for changing CInByteStream / COutByteStreamBasic object's byte order, both permanently and temporarily.
| |
void | net_order (NS_IMPL::CDataStreamBase &ds) |
void | host_order (NS_IMPL::CDataStreamBase &ds) |
void | little_endian (NS_IMPL::CDataStreamBase &ds) |
void | big_endian (NS_IMPL::CDataStreamBase &ds) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< T > | net_order_value (T &val) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< const T > | net_order_value (const T &val) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< T > | host_order_value (T &val) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< const T > | host_order_value (const T &val) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< T > | little_endian_value (T &val) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< const T > | little_endian_value (const T &val) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< T > | big_endian_value (T &val) |
template<class T > | |
NS_IMPL::CManipulatorValueByteOrder< const T > | big_endian_value (const T &val) |
Current position | |
APIs for changing current position, both permanently and temporarily.
| |
NS_IMPL::CManipulatorSeek | seek (size_t pos) |
NS_IMPL::CManipulatorSkip | skip (ssize_t off) |
NS_IMPL::CManipulatorSkipFill | skip (ssize_t off, int fill) |
template<typename T > | |
NS_IMPL::CManipulatorSkipPtr< T > | skip (T *off) |
template<typename T > | |
NS_IMPL::CManipulatorSkipPtrFill< T > | skip (T *off, int fill) |
template<class T > | |
NS_IMPL::CManipulatorOffsetValue< T > | offset_value (size_t pos, T &val) |
template<class T > | |
NS_IMPL::CManipulatorOffsetValue< const T > | offset_value (size_t pos, const T &val) |
template<class T > | |
NS_IMPL::CManipulatorInsert< T > | insert (size_t pos, const T &val) |
Manip::end | |
End packing/unpacking operations. When all packing/unpacking operations finish, it's a good practice to announce an
| |
NS_IMPL::CManipulatorEnd< void, void > | end () |
End operations for CInByteStream, COutByteStreamStrRef, COutByteStreamVecRef. More... | |
template<typename SizeT > | |
NS_IMPL::CManipulatorEnd< SizeT *, void > | end (SizeT *sz) |
End operations for COutByteStreamBuf, COutByteStreamStrRef, COutByteStreamVecRef. More... | |
template<class BufT > | |
NS_IMPL::CManipulatorEnd< BufT, void > | end (BufT &buf) |
End operations for COutByteStream / COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef. More... | |
template<typename CharT > | |
NS_IMPL::CManipulatorEnd< CharT *, size_t * > | end (CharT *buf, size_t *sz) |
End operations for COutByteStream / COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef, COutByteStreamBuf. More... | |
Manipulators for stream interface APIs.
|
inline |
End operations for CInByteStream, COutByteStreamStrRef, COutByteStreamVecRef.
Sample code for CInByteStream:
Sample code for COutByteStreamBasic:
|
inline |
End operations for COutByteStreamBuf, COutByteStreamStrRef, COutByteStreamVecRef.
This manipulator will also store the byte size of underlying data buffer in sz
.
Sample code:
SizeT | Type of an integer |
[out] | sz | Pointer to an integer to receive the size of actual data |
|
inline |
End operations for COutByteStream / COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef.
This manipulator will also export data to buf
. If it's not empty, new data will append to it.
Sample code:
buf
is empty and the underlying buffer is internal (COutByteStream / COutByteStreamStr and COutByteStreamVec). BufT | Must be the same as the underlying buffer type, e.g. std::string for COutByteStream / COutByteStreamStr, COutByteStreamStrRef, or std::vector<char> for COutByteStreamVec, COutByteStreamVecRef |
[out] | buf | A buffer to receive data |
|
inline |
End operations for COutByteStream / COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef, COutByteStreamBuf.
Sample code;
CharT | Must be the same as the underlying character type, e.g. char |
[out] | buf | Pointer to a byte array to receive the data |
[in,out] | sz | Pass in as the length of dst ; pass out as the real size of exported data |
|
inline |
Pack/unpack Protocol Buffers messages.
This manipulator makes protobuf messages easily cooperative with other data formats. Packing/unpacking a protobuf message is as simple as for an integer. Boundary checks are automatically done, data pointers are efficiently handled.
Sample code for CInByteStream:
By default, Manip::protobuf will use all left data of in
to initialize protobuf message object, which means the message should be the last value of in
.
But if that's not the case, you must provide a size parameter to limit the reading:
in
will be set to non-zero.Sample code for COutByteStreamBasic:
T | Any subclass of google::protobuf::MessageLite |
[in,out] | msg | A message object |
[in] | size | Size of bytes read when unpacking msg |
|
inline |
Set up a stub.
Any packing/unpacking operation cannot go beyond the stub, or it fails with status set to non-zero.
Stubs can stack, the top most one is currently in effect. After popping up it, the next top one takes effect immediately, until there is no stubs.
A common use of stubs is to create a robust hierarchical data structure in which errors in one part never affect other parts. Besides, additional boundary checks make defects harder to hide.
When creating a stub, you need provide offset of the stub, sz
, relative to current pointer, i.e. the position of the stub is cur() + sz
.
Sample code for CInByteStream:
Sample code for COutByteStreamBasic:
sz | Offset of the stub, relative to current pointer |
|
inline |
Demolish the top most stub.
This manipulator demolishes current stub, check and align current pointer if needed. The next top stub will take effect, until there is no stubs any more.
Sample code for CInByteStream:
Sample code for COutByteStreamBasic:
align |
|
check |
|
|
inline |
Pack integer using Base 128 Varints encoding.
Varint encoding is compact, byte order independent, and efficient. This manipulator makes it super easy to take advantage of it, and supports all primitive integer types, from char
to wchar_t
to long long
.
Sample Code:
T | An integer type |
val | An integer |
|
inline |
Unpack integer using Base 128 Varints encoding.
Sample Code:
T | An integer type |
[out] | val | An integer to receive the result |