25 #ifndef DOZERG_DATA_STREAM_H_20070905 26 #define DOZERG_DATA_STREAM_H_20070905 206 template<
class T,
size_t N>
207 inline NS_IMPL::CManipulatorRawPtr<T> raw(T (&c)[N]){
208 return NS_IMPL::CManipulatorRawPtr<T>(c, N);
212 inline NS_IMPL::CManipulatorRawPtr<T> raw(T * c,
size_t sz){
213 return NS_IMPL::CManipulatorRawPtr<T>(c, sz);
217 inline NS_IMPL::CManipulatorRawPtr<T> raw(std::vector<T> & c,
size_t sz){
218 const size_t old = c.size();
220 return NS_IMPL::CManipulatorRawPtr<T>(&c[old], sz);
224 inline NS_IMPL::CManipulatorRawPtr<const T> raw(
const std::vector<T> & c,
size_t * sz = NULL){
227 return NS_IMPL::CManipulatorRawPtr<const T>(&c[0], c.size());
230 template<
typename Char>
231 inline NS_IMPL::CManipulatorRawPtr<Char> raw(std::basic_string<Char> & c,
size_t len){
232 const size_t old = c.size();
234 return NS_IMPL::CManipulatorRawPtr<Char>(&c[old], len);
237 template<
typename Char>
238 inline NS_IMPL::CManipulatorRawPtr<const Char> raw(
const std::basic_string<Char> & c,
size_t * sz = NULL){
241 return NS_IMPL::CManipulatorRawPtr<const Char>(c.c_str(), c.size());
244 template<
class ForwardIter>
245 inline NS_IMPL::CManipulatorRawRange<ForwardIter> raw(ForwardIter first, ForwardIter last,
size_t * sz = NULL){
246 return NS_IMPL::CManipulatorRawRange<ForwardIter>(first, last, sz);
250 inline NS_IMPL::CManipulatorRawCont<T> raw(T & c,
size_t sz){
251 return NS_IMPL::CManipulatorRawCont<T>(c, sz, NULL);
255 inline NS_IMPL::CManipulatorRawCont<const T> raw(
const T & c,
size_t * sz = NULL){
256 return NS_IMPL::CManipulatorRawCont<const T>(c, 0, sz);
493 template<
typename LenT,
class T,
size_t N>
494 inline NS_IMPL::CManipulatorArrayPtr<LenT, T> array(T (&c)[N], LenT * real_sz){
495 return NS_IMPL::CManipulatorArrayPtr<LenT, T>(c, N, real_sz);
498 template<
typename LenT,
class T,
size_t N>
499 inline NS_IMPL::CManipulatorArrayPtr<LenT, const T> array(
const T (&c)[N]){
500 return NS_IMPL::CManipulatorArrayPtr<LenT, const T>(c, N, NULL);
503 template<
typename LenT,
class T>
504 inline NS_IMPL::CManipulatorArrayPtr<LenT, T> array(T * c,
size_t sz, LenT * real_sz){
505 return NS_IMPL::CManipulatorArrayPtr<LenT, T>(c, sz, real_sz);
508 template<
typename LenT,
class T>
509 inline NS_IMPL::CManipulatorArrayPtr<LenT, const T> array(
const T * c,
size_t sz){
510 return NS_IMPL::CManipulatorArrayPtr<LenT, const T>(c, sz, NULL);
513 template<
typename LenT,
class T>
514 inline NS_IMPL::CManipulatorArrayCont<LenT, T> array(T & c, LenT max_size = 0){
515 return NS_IMPL::CManipulatorArrayCont<LenT, T>(c, max_size);
518 template<
typename LenT,
class T>
519 inline NS_IMPL::CManipulatorArrayCont<LenT, const T> array(
const T & c){
520 return NS_IMPL::CManipulatorArrayCont<LenT, const T>(c, 0);
524 inline NS_IMPL::CManipulatorArrayCont<uint16_t, T> array(T & c, uint16_t max_size = 0){
525 return NS_IMPL::CManipulatorArrayCont<uint16_t, T>(c, max_size);
529 inline NS_IMPL::CManipulatorArrayCont<uint16_t, const T> array(
const T & c){
530 return NS_IMPL::CManipulatorArrayCont<uint16_t, const T>(c, 0);
533 template<
typename LenT,
class ForwardIter>
534 inline NS_IMPL::CManipulatorArrayRange<LenT, ForwardIter> array(ForwardIter first, ForwardIter last, LenT * sz = NULL){
535 return NS_IMPL::CManipulatorArrayRange<LenT, ForwardIter>(first, last, sz);
594 inline void net_order(NS_IMPL::CDataStreamBase & ds){ds.netByteOrder(
true);}
596 inline void host_order(NS_IMPL::CDataStreamBase & ds){ds.netByteOrder(
false);}
598 inline void little_endian(NS_IMPL::CDataStreamBase & ds){ds.littleEndian(
true);}
600 inline void big_endian(NS_IMPL::CDataStreamBase & ds){ds.littleEndian(
false);}
603 inline NS_IMPL::CManipulatorValueByteOrder<T> net_order_value(T & val){
604 return NS_IMPL::CManipulatorValueByteOrder<T>(val, net_order);
608 inline NS_IMPL::CManipulatorValueByteOrder<const T> net_order_value(
const T & val){
609 return NS_IMPL::CManipulatorValueByteOrder<const T>(val, net_order);
613 inline NS_IMPL::CManipulatorValueByteOrder<T> host_order_value(T & val){
614 return NS_IMPL::CManipulatorValueByteOrder<T>(val, host_order);
618 inline NS_IMPL::CManipulatorValueByteOrder<const T> host_order_value(
const T & val){
619 return NS_IMPL::CManipulatorValueByteOrder<const T>(val, host_order);
623 inline NS_IMPL::CManipulatorValueByteOrder<T> little_endian_value(T & val){
624 return NS_IMPL::CManipulatorValueByteOrder<T>(val, little_endian);
628 inline NS_IMPL::CManipulatorValueByteOrder<const T> little_endian_value(
const T & val){
629 return NS_IMPL::CManipulatorValueByteOrder<const T>(val, little_endian);
633 inline NS_IMPL::CManipulatorValueByteOrder<T> big_endian_value(T & val){
634 return NS_IMPL::CManipulatorValueByteOrder<T>(val, big_endian);
638 inline NS_IMPL::CManipulatorValueByteOrder<const T> big_endian_value(
const T & val){
639 return NS_IMPL::CManipulatorValueByteOrder<const T>(val, big_endian);
709 inline NS_IMPL::CManipulatorSeek seek(
size_t pos){
return NS_IMPL::CManipulatorSeek(pos);}
711 inline NS_IMPL::CManipulatorSkip skip(ssize_t off){
return NS_IMPL::CManipulatorSkip(off);}
713 inline NS_IMPL::CManipulatorSkipFill skip(ssize_t off,
int fill){
return NS_IMPL::CManipulatorSkipFill(off, fill);}
716 inline NS_IMPL::CManipulatorSkipPtr<T> skip(T * off){
return NS_IMPL::CManipulatorSkipPtr<T>(off);}
719 inline NS_IMPL::CManipulatorSkipPtrFill<T> skip(T * off,
int fill){
return NS_IMPL::CManipulatorSkipPtrFill<T>(off);}
722 inline NS_IMPL::CManipulatorOffsetValue<T> offset_value(
size_t pos, T & val){
723 return NS_IMPL::CManipulatorOffsetValue<T>(pos, val);
727 inline NS_IMPL::CManipulatorOffsetValue<const T> offset_value(
size_t pos,
const T & val){
728 return NS_IMPL::CManipulatorOffsetValue<const T>(pos, val);
732 inline NS_IMPL::CManipulatorInsert<T> insert(
size_t pos,
const T & val){
733 return NS_IMPL::CManipulatorInsert<T>(pos, val);
773 inline NS_IMPL::CManipulatorProtobuf<T>
protobuf(T & msg,
size_t size =
size_t(-1)){
774 return NS_IMPL::CManipulatorProtobuf<T>(msg, size);
793 inline NS_IMPL::CManipulatorVarint<const T>
varint(
const T & val){
794 return NS_IMPL::CManipulatorVarint<const T>(val);
811 inline NS_IMPL::CManipulatorVarint<T>
varint(T & val){
812 return NS_IMPL::CManipulatorVarint<T>(val);
845 inline NS_IMPL::CManipulatorStubPush
stub(
size_t sz){
846 return NS_IMPL::CManipulatorStubPush(sz);
884 inline NS_IMPL::CManipulatorStubPop
stub_pop(
bool align =
false,
bool check =
false){
885 return NS_IMPL::CManipulatorStubPop(align, check);
929 inline NS_IMPL::CManipulatorEnd<void, void>
end(){
930 return NS_IMPL::CManipulatorEnd<void, void>();
951 template<
typename SizeT>
952 inline NS_IMPL::CManipulatorEnd<SizeT *, void>
end(SizeT * sz){
953 return NS_IMPL::CManipulatorEnd<SizeT *, void>(sz);
979 inline NS_IMPL::CManipulatorEnd<BufT, void>
end(BufT & buf){
980 return NS_IMPL::CManipulatorEnd<BufT, void>(buf);
1003 template<
typename CharT>
1004 inline NS_IMPL::CManipulatorEnd<CharT *, size_t *>
end(CharT * buf,
size_t * sz){
1005 return NS_IMPL::CManipulatorEnd<CharT *, size_t *>(buf, sz);
1035 typedef NS_IMPL::CDataStreamBase __MyBase;
1047 : __MyBase(kByteOrderDefault, 1)
1061 setSource(buf, sz, net);
1071 CInByteStream(
const unsigned char * buf,
size_t sz,
bool net = kByteOrderDefault){
1072 setSource(buf, sz, net);
1082 CInByteStream(
const signed char * buf,
size_t sz,
bool net = kByteOrderDefault){
1083 setSource(buf, sz, net);
1093 setSource(buf, net);
1104 void setSource(
const char * buf,
size_t sz,
bool net = kByteOrderDefault){
1120 void setSource(
const unsigned char * buf,
size_t sz,
bool net = kByteOrderDefault){
1121 setSource(reinterpret_cast<const char *>(buf), sz, net);
1132 void setSource(
const signed char * buf,
size_t sz,
bool net = kByteOrderDefault){
1133 setSource(reinterpret_cast<const char *>(buf), sz, net);
1142 void setSource(
const std::string & buf,
bool net = kByteOrderDefault){
1143 setSource(buf.c_str(), buf.size(), net);
1173 return (cur_ = pos);
1184 ssize_t
skip(ssize_t off){
return seek(cur() + off);}
1191 size_t cur()
const{
return cur_;}
1199 const char *
data()
const{
return (data_ + cur());}
1206 size_t left()
const{
return (getStub(len_) - cur());}
1213 oss<<
"{CDataStreamBase="<<__MyBase::toString()
1215 <<
", data_="<<NS_IMPL::dumpBufPart(data_, len_, cur_)
1227 __Myt & operator >>(
char & c) {
return readPod(c);}
1228 __Myt & operator >>(
signed char & c) {
return readPod(c);}
1229 __Myt & operator >>(
unsigned char & c) {
return readPod(c);}
1230 __Myt & operator >>(
short & c) {
return readPod(c);}
1231 __Myt & operator >>(
unsigned short & c) {
return readPod(c);}
1232 __Myt & operator >>(
int & c) {
return readPod(c);}
1233 __Myt & operator >>(
unsigned int & c) {
return readPod(c);}
1234 __Myt & operator >>(
long & c) {
return readPod(c);}
1235 __Myt & operator >>(
unsigned long & c) {
return readPod(c);}
1236 __Myt & operator >>(
long long & c) {
return readPod(c);}
1237 __Myt & operator >>(
unsigned long long & c) {
return readPod(c);}
1238 __Myt & operator >>(
wchar_t & c) {
return readPod(c);}
1250 __Myt & operator >>(std::string & c){
return (*
this>>Manip::array(c));}
1258 __Myt & operator >>(std::wstring & c){
return (*
this>>Manip::array(c));}
1269 template<
class T,
size_t N>
1270 __Myt & operator >>(T (&c)[N]){
return readRaw(c, N);}
1280 __Myt & operator >>(
void (*m)(__MyBase &)){
1286 __Myt & operator >>(
const NS_IMPL::CManipulatorRawPtr<T> & m){
1287 return readRaw(m.c_, m.sz_);
1290 __Myt & operator >>(
const NS_IMPL::CManipulatorRawCont<T> & m){
1291 typedef typename T::value_type __Val;
1292 for(
size_t i = 0;good() && i < m.sz_;++i){
1295 m.c_.insert(m.c_.end(), v);
1299 template<
class ForwardIter>
1300 __Myt & operator >>(
const NS_IMPL::CManipulatorRawRange<ForwardIter> & m){
1302 for(ForwardIter i = m.beg_;good() && i != m.end_;++i, ++sz)
1308 template<
typename LenT,
class T>
1309 __Myt & operator >>(
const NS_IMPL::CManipulatorArrayPtr<LenT, T> & m){
1312 if(
size_t(sz) > m.sz1_)
1314 if((*
this>>Manip::raw(m.c_, sz)) && m.sz2_)
1319 template<
typename LenT,
class T>
1320 __Myt & operator >>(
const NS_IMPL::CManipulatorArrayCont<LenT, T> & m){
1321 __UNUSED
typedef typename T::value_type __Val;
1324 if(m.max_ && sz > m.max_)
1326 *
this>>Manip::raw(m.c_, sz);
1331 __Myt & operator >>(
const NS_IMPL::CManipulatorValueByteOrder<T> & m){
1332 const bool old = littleEndian();
1333 *
this>>m.fun_>>m.c_;
1337 __Myt & operator >>(
const NS_IMPL::CManipulatorSeek & m){
1341 __Myt & operator >>(
const NS_IMPL::CManipulatorSkip & m){
1345 template<
typename T>
1346 __Myt & operator >>(
const NS_IMPL::CManipulatorSkipPtr<T> & m){
1352 __Myt & operator >>(
const NS_IMPL::CManipulatorOffsetValue<T> & m){
1353 const size_t old = cur();
1354 if(seek(m.pos_) >= 0 && (*
this>>m.c_))
1359 __Myt & operator >>(
const NS_IMPL::CManipulatorProtobuf<T> & m){
1363 if(!m.c_.ParseFromArray(data(), sz))
1368 template<
typename T>
1369 __Myt & operator >>(
const NS_IMPL::CManipulatorVarint<T> & m){
1370 typename NS_IMPL::CManipulatorVarint<T>::__Unsigned v = 0;
1375 __Myt & operator >>(
const NS_IMPL::CManipulatorStubPush & m){
1376 pushStub(m.sz_ + cur());
1379 __Myt & operator >>(
const NS_IMPL::CManipulatorStubPop & m){
1382 if(m.check_ && cur() != pos)
1384 seek(m.align_ ? pos : cur());
1388 template<
class T,
class S>
1389 __Myt & operator >>(
const NS_IMPL::CManipulatorEnd<T, S> & m){
1390 if(clearStub() && left())
1394 __Myt & operator >>(NS_IMPL::CManipulatorEnd<void, void> (*m)()){
1397 return (*
this>>m());
1402 template<
typename T>
1403 __Myt & readPod(T & c){
1404 if(ensure(
sizeof(T))){
1405 memcpy(&c, data(),
sizeof(T));
1406 if(
sizeof(T) > 1 && needReverse())
1407 c = tools::SwapByteOrder(c);
1412 __Myt & readVarint(
unsigned char & c){
1418 c |= data_[cur_++] << 7;
1422 template<
typename T>
1423 __Myt & readVarint(T & c){
1429 c = (c & ((1 << 7) - 1)) | (data_[cur_++] << 7);
1433 for(uint8_t v = -1, s = 14;v > 0x7F && readPod(v);s += 7)
1434 c |= T(v & 0x7F) << s;
1439 template<
typename T>
1440 __Myt & readRaw(T * c,
size_t sz){
1446 || (
sizeof(T) > 1 && needReverse())){
1447 for(
size_t i = 0;good() && i < sz;++i, ++c)
1452 memcpy(c, data(), sz);
1458 bool ensure(
size_t sz){
1459 if(checkStub(cur() + sz)){
1526 template<
class Data>
1529 typedef NS_IMPL::CDataStreamBase __MyBase;
1531 typedef Data __Data;
1533 typedef typename Data::__Buf buffer_type;
1534 typedef typename Data::__Char char_type;
1605 size_t cur()
const{
return data_.cur();}
1623 if(!checkStub(cur() + off))
1625 if(off < 0 &&
size_t(-off) > cur()){
1629 return seek(cur() + off);
1641 ssize_t
skip(ssize_t off,
int fill){
1642 const size_t old = cur();
1643 const ssize_t ret = skip(off);
1646 if(old <
size_t(ret))
1647 std::fill(data_.data(old), data_.data(ret), fill);
1656 oss<<
"{CDataStreamBase="<<__MyBase::toString()
1657 <<
", data_="<<data_.toString()
1669 __Myt & operator <<(
char c) {
return writePod(c);}
1670 __Myt & operator <<(
signed char c) {
return writePod(c);}
1671 __Myt & operator <<(
unsigned char c) {
return writePod(c);}
1672 __Myt & operator <<(
short c) {
return writePod(c);}
1673 __Myt & operator <<(
unsigned short c) {
return writePod(c);}
1674 __Myt & operator <<(
int c) {
return writePod(c);}
1675 __Myt & operator <<(
unsigned int c) {
return writePod(c);}
1676 __Myt & operator <<(
long c) {
return writePod(c);}
1677 __Myt & operator <<(
unsigned long c) {
return writePod(c);}
1678 __Myt & operator <<(
long long c) {
return writePod(c);}
1679 __Myt & operator <<(
unsigned long long c) {
return writePod(c);}
1680 __Myt & operator <<(
wchar_t c) {
return writePod(c);}
1692 __Myt & operator <<(
const std::string & c){
return (*
this<<Manip::array(c));}
1700 __Myt & operator <<(
const std::wstring & c){
return (*
this<<Manip::array(c));}
1711 template<
class T,
size_t N>
1712 __Myt & operator <<(
const T (&c)[N]){
return writeRaw(c, N);}
1723 __Myt & operator <<(const NS_IMPL::CManipulatorRawPtr<T> & m){
1724 return writeRaw(m.c_, m.sz_);
1727 __Myt & operator <<(const NS_IMPL::CManipulatorRawCont<T> & m){
1728 const size_t sz = writeRange(m.c_.begin(), m.c_.end());
1733 template<
class ForwardIter>
1734 __Myt & operator <<(const NS_IMPL::CManipulatorRawRange<ForwardIter> & m){
1735 const size_t sz = writeRange(m.beg_, m.end_);
1740 template<
typename LenT,
class T>
1741 __Myt & operator <<(const NS_IMPL::CManipulatorArrayPtr<LenT, T> & m){
1742 if(*
this<<LenT(m.sz1_))
1743 writeRaw(m.c_, m.sz1_);
1746 template<
typename LenT,
class T>
1747 __Myt & operator <<(const NS_IMPL::CManipulatorArrayCont<LenT, T> & m){
1748 const size_t off = cur();
1750 if((*
this<<LenT(0)) && !m.c_.empty()){
1752 if((*
this<<Manip::raw(m.c_, &sz)))
1753 *
this<<Manip::offset_value(off, LenT(sz));
1757 template<
typename LenT,
class ForwardIter>
1758 __Myt & operator <<(const NS_IMPL::CManipulatorArrayRange<LenT, ForwardIter> & m){
1759 const size_t off = cur();
1761 if((*
this<<LenT(0)<<Manip::raw(m.beg_, m.end_, &sz))){
1762 *
this<<Manip::offset_value(off, LenT(sz));
1768 __Myt & operator <<(
void (*m)(__MyBase &)){
1774 __Myt & operator <<(const NS_IMPL::CManipulatorValueByteOrder<T> & m){
1775 const bool old = littleEndian();
1776 *
this<<m.fun_<<m.c_;
1780 __Myt & operator <<(
const NS_IMPL::CManipulatorSeek & m){
1784 __Myt & operator <<(
const NS_IMPL::CManipulatorSkip & m){
1788 __Myt & operator <<(
const NS_IMPL::CManipulatorSkipFill & m){
1789 skip(m.off_, m.fill_);
1792 template<
typename T>
1793 __Myt & operator <<(const NS_IMPL::CManipulatorSkipPtr<T> & m){
1798 template<
typename T>
1799 __Myt & operator <<(const NS_IMPL::CManipulatorSkipPtrFill<T> & m){
1801 skip(*m.off_, m.fill_);
1805 __Myt & operator <<(const NS_IMPL::CManipulatorOffsetValue<T> & m){
1806 const size_t old = cur();
1807 if(seek(m.pos_) >= 0 && (*
this<<m.c_))
1812 __Myt & operator <<(const NS_IMPL::CManipulatorInsert<T> & m){
1814 const size_t old = cur();
1816 if(old == m.pos_ || seek(m.pos_) >= 0)
1820 __OutStream ds(buf);
1821 if(!(ds<<m.c_) || !ds.finish())
1823 if(!buf.empty() && ensure(buf.size()))
1824 data_.insert(m.pos_, cast(buf.c_str()), buf.size());
1829 __Myt & operator <<(const NS_IMPL::CManipulatorProtobuf<T> & m){
1830 const size_t old = size();
1831 const size_t sz = m.c_.ByteSize();
1832 if(skip(sz) >= 0 && !m.c_.SerializeToArray(data_.data(old), sz)){
1838 template<
typename T>
1839 __Myt & operator <<(const NS_IMPL::CManipulatorVarint<T> & m){
1840 return writeVarint(m.toUnsigned());
1842 __Myt & operator <<(
const NS_IMPL::CManipulatorStubPush & m){
1843 pushStub(m.sz_ + cur());
1846 __Myt & operator <<(
const NS_IMPL::CManipulatorStubPop & m){
1849 if(m.check_ && cur() != pos)
1851 seek(m.align_ ? pos : cur());
1855 __Myt & operator <<(const NS_IMPL::CManipulatorEnd<void, void> & m){
1859 __Myt & operator <<(NS_IMPL::CManipulatorEnd<void, void> (*m)()){
1862 return (*
this<<m());
1864 template<
typename SizeT>
1865 __Myt & operator <<(const NS_IMPL::CManipulatorEnd<SizeT *, void> & m){
1869 __Myt & operator <<(const NS_IMPL::CManipulatorEnd<buffer_type, void> & m){
1873 template<
typename CharT>
1874 __Myt & operator <<(const NS_IMPL::CManipulatorEnd<CharT *, size_t *> & m){
1875 finish(m.buf_, m.sz_);
1888 if(good() && !data_.exportData())
1903 template<
typename SizeT>
1905 if(good() && !data_.exportData(sz))
1920 if(good() && !data_.exportData(dst))
1935 template<
typename CharT>
1937 if(good() && !data_.exportData(dst, sz))
1942 __Myt & operator <<(
bool);
1943 template<
typename T>
1944 static const char_type * cast(
const T * c){
1945 return reinterpret_cast<const char_type *
>(c);
1947 template<
typename T>
1948 __Myt & writePod(T c){
1949 if(ensure(
sizeof(T))){
1950 if(
sizeof(T) > 1 && needReverse())
1951 c = tools::SwapByteOrder(c);
1952 data_.append(cast(&c),
sizeof(T));
1956 __Myt & writeVarint(
unsigned char c){
1960 }
else if(ensure(2)){
1961 data_.append(c | 0x80);
1962 data_.append(c >> 7);
1966 __Myt & writeVarint(
unsigned short c){
1970 }
else if(c < (1 << 14)){
1972 data_.append(c | 0x80);
1973 data_.append(c >> 7);
1975 }
else if(ensure(3)){
1976 data_.append(c | 0x80);
1977 data_.append((c >> 7) | 0x80);
1978 data_.append(c >> 14);
1982 template<
typename T>
1983 __Myt & writeVarint(T c){
1987 }
else if(c < (1 << 14)){
1989 data_.append(c | 0x80);
1990 data_.append(c >> 7);
1992 }
else if(c < (1 << 21)){
1994 data_.append(c | 0x80);
1995 data_.append((c >> 7) | 0x80);
1996 data_.append(c >> 14);
1998 }
else if(c < (1 << 28)){
2000 data_.append(c | 0x80);
2001 data_.append((c >> 7) | 0x80);
2002 data_.append((c >> 14) | 0x80);
2003 data_.append(c >> 21);
2005 }
else if(ensure(5)){
2006 data_.append(c | 0x80);
2007 data_.append((c >> 7) | 0x80);
2008 data_.append((c >> 14) | 0x80);
2009 data_.append((c >> 21) | 0x80);
2016 data_.append(c | 0x80);
2022 template<
typename T>
2023 __Myt & writeRaw(
const T * c,
size_t sz){
2029 || (
sizeof(T) > 1 && needReverse())){
2030 for(
size_t i = 0;good() && i < sz;++i,++c)
2035 data_.append(cast(c), sz);
2039 template<
class ForwardIter>
2040 size_t writeRange(ForwardIter first, ForwardIter last){
2042 for(ForwardIter i = first;good() && i != last;++i, ++c)
2046 bool ensure(
size_t len){
2047 if(!checkStub(cur() + len))
2049 if(data_.ensure(len))
COutByteStreamBasic< NS_IMPL::__buf_data< std::string > > COutByteStreamStr
Use internal std::string as the underlying data buffer.
Definition: data_stream.hh:2059
ssize_t skip(ssize_t off, int fill)
Skip some bytes.
Definition: data_stream.hh:1641
NS_IMPL::CManipulatorStubPop stub_pop(bool align=false, bool check=false)
Demolish the top most stub.
Definition: data_stream.hh:884
CInByteStream(const char *buf, size_t sz, bool net=kByteOrderDefault)
Construct from a byte buffer.
Definition: data_stream.hh:1060
Definition: to_string.hh:43
size_t size() const
Get byte size of data have been written, same as cur.
Definition: data_stream.hh:1611
__Myt & bad(int code)
Set status.
Definition: data_stream.hh:1577
COutByteStreamBasic(size_t reserve=1024, bool net=kByteOrderDefault)
Constructor for COutByteStream/COutByteStreamStr, COutByteStreamVec.
Definition: data_stream.hh:1542
ssize_t seek(size_t pos)
Set current pointer.
Definition: data_stream.hh:1166
ssize_t skip(ssize_t off)
Skip some data.
Definition: data_stream.hh:1184
COutByteStreamBasic< NS_IMPL::__buf_data< CCharBuffer< char > > > COutByteStreamBuf
Use external char array as the underlying data buffer.
Definition: data_stream.hh:2074
bool finish(CharT *dst, size_t *sz)
Export data for COutByteStream/COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef, COutByteStreamBuf.
Definition: data_stream.hh:1936
std::string toString() const
Get a readable description of this object.
Definition: data_stream.hh:1654
Definition: template.hh:23
COutByteStreamBasic< NS_IMPL::__buf_data< std::vector< char > > > COutByteStreamVec
Use internal std::vector<char> as the underlying data buffer.
Definition: data_stream.hh:2068
NS_IMPL::CManipulatorProtobuf< T > protobuf(T &msg, size_t size=size_t(-1))
Pack/unpack Protocol Buffers messages.
Definition: data_stream.hh:773
COutByteStreamStr COutByteStream
Same as COutByteStreamStr.
Definition: data_stream.hh:2062
Manipulators for stream interface APIs.
Definition: data_stream.hh:41
void setSource(const signed char *buf, size_t sz, bool net=kByteOrderDefault)
Initialize with a byte buffer.
Definition: data_stream.hh:1132
bool finish(SizeT *sz)
Export data for COutByteStreamBuf, COutByteStreamStrRef, COutByteStreamVecRef.
Definition: data_stream.hh:1904
Data unpacking interfaces.
Definition: data_stream.hh:1033
bool finish()
Export data for COutByteStreamStrRef, COutByteStreamVecRef.
Definition: data_stream.hh:1887
void setSource(const char *buf, size_t sz, bool net=kByteOrderDefault)
Initialize with a byte buffer.
Definition: data_stream.hh:1104
COutByteStreamBasic< NS_IMPL::__buf_ref_data< std::string > > COutByteStreamStrRef
Use external std::string as the underlying data buffer.
Definition: data_stream.hh:2065
void setSource(const unsigned char *buf, size_t sz, bool net=kByteOrderDefault)
Initialize with a byte buffer.
Definition: data_stream.hh:1120
CInByteStream(const std::string &buf, bool net=kByteOrderDefault)
Construct from a byte buffer.
Definition: data_stream.hh:1092
void setSource(const std::string &buf, bool net=kByteOrderDefault)
Initialize with a byte buffer.
Definition: data_stream.hh:1142
const char * data() const
Get a pointer to left data.
Definition: data_stream.hh:1199
size_t cur() const
Get current pointer.
Definition: data_stream.hh:1191
std::string toString() const
Get a readable description of this object.
Definition: data_stream.hh:1211
NS_IMPL::CManipulatorStubPush stub(size_t sz)
Set up a stub.
Definition: data_stream.hh:845
CInByteStream(const signed char *buf, size_t sz, bool net=kByteOrderDefault)
Construct from a byte buffer.
Definition: data_stream.hh:1082
Implementation of CInByteStream, COutByteStreamBasic.
bool finish(buffer_type &dst)
Export data for COutByteStream/COutByteStreamStr, COutByteStreamStrRef, COutByteStreamVec, COutByteStreamVecRef.
Definition: data_stream.hh:1919
NS_IMPL::CManipulatorVarint< const T > varint(const T &val)
Pack integer using Base 128 Varints encoding.
Definition: data_stream.hh:793
COutByteStreamBasic(char_type *buf, size_t sz, bool net=kByteOrderDefault)
Constructor for COutByteStreamBuf.
Definition: data_stream.hh:1565
COutByteStreamBasic(buffer_type &buf, bool net=kByteOrderDefault)
Constructor for COutByteStreamStrRef, COutByteStreamVecRef.
Definition: data_stream.hh:1553
ssize_t seek(size_t pos)
Set current pointer.
Definition: data_stream.hh:1590
NS_IMPL::CManipulatorEnd< void, void > end()
End operations for CInByteStream, COutByteStreamStrRef, COutByteStreamVecRef.
Definition: data_stream.hh:929
size_t left() const
Get byte size of left data.
Definition: data_stream.hh:1206
COutByteStreamBasic< NS_IMPL::__buf_ref_data< std::vector< char > > > COutByteStreamVecRef
Use external std::vector<char> as the underlying data buffer.
Definition: data_stream.hh:2071
Data packing interfaces.
Definition: data_stream.hh:1527
__Myt & bad(int code)
Set status.
Definition: data_stream.hh:1153
CInByteStream()
Construct an empty object.
Definition: data_stream.hh:1046
size_t cur() const
Get current pointer.
Definition: data_stream.hh:1605
CInByteStream(const unsigned char *buf, size_t sz, bool net=kByteOrderDefault)
Construct from a byte buffer.
Definition: data_stream.hh:1071
ssize_t skip(ssize_t off)
Skip some bytes.
Definition: data_stream.hh:1622