Cbytebuffer use
Static void Main () { BYTE A; Short b; int C; Cbytebuffer buffer; Buffer<<a<<b<<c;}
Classcbytebuffer{ Public: BYTE*M_lpbuf; intNcurrentindex; intncapacity; intNlen; Cbytebuffer () {Init ( -); } cbytebuffer (intNcapacityin) {Init (Ncapacityin); } ~Cbytebuffer () {delete [] m_lpbuf; M_lpbuf=NULL; } voidgetmorecapacity () {BYTE*pbytesmore=Newbyte[ncapacity*2];//twice timesmemcpy (pbytesmore,m_lpbuf,ncapacity*sizeof(BYTE)); memset (Pbytesmore+ncapacity,0x00, ncapacity*sizeof(BYTE)); delete [] m_lpbuf; M_lpbuf=Pbytesmore; Ncapacity*=2; } template<typename t>Cbytebuffer&operator<<(T DW) {intNsizenew=ncurrentindex +sizeof(T); while(nsizenew>ncapacity) {getmorecapacity ();//Insufficient Buffer space } * (t*) (&m_lpbuf[ncurrentindex]) =DW;//Add bufferNcurrentindex + =sizeof(T);//Move Current Indexnlen+=sizeof(T); return* This; }Private: voidInit (intNcapatityin) {ncapacity=Ncapatityin; M_lpbuf=NewByte[ncapatityin]; memset (M_lpbuf,0x00, ncapacity); Ncurrentindex=0; Nlen=0; }};
C + + byte stream cbytebuffer