📄 streambase.cpp.bak
字号:
#include "StreamBase.h"
using namespace Stream;
CNetStream & CNetStream::operator << (unsigned char val)
{
if (m_socket.Write(&val,sizeof(val)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
CNetStream & CNetStream::operator << (unsigned short val)
{
unsigned char buf[2];
buf[0] = (val >> 8) & 0xff;
buf[1] = (val & 0xff);
if (m_socket.Write(buf,sizeof(buf)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
CNetStream & CNetStream::operator << (unsigned long val)
{
unsigned char buf[4];
buf[0] = (unsigned char)((val >> 24) & 0xff);
buf[1] = (unsigned char)((val >> 16) & 0xff);
buf[2] = (unsigned char)((val >> 8) & 0xff);
buf[3] = (unsigned char)(val & 0xff);
if (m_socket.Write(buf,sizeof(buf)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
CNetStream & CNetStream::operator << (unsigned int val)
{
unsigned char buf[4];
buf[0] = (val >> 24) & 0xff;
buf[1] = (val >> 16) & 0xff;
buf[2] = (val >> 8) & 0xff;
buf[3] = (val & 0xff);
if (m_socket.Write(buf,sizeof(buf)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
// CUInt128 store the high byte first
CNetStream & CNetStream::operator << (const CUInt128& val)
{
byte* buf = val.GetDataPtr();
if(m_socket.Write(buf,16) != 16)
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
CNetStream & CNetStream::operator << (const char * lpszInfo)
{
int nLength = strlen(lpszInfo);
if (m_socket.Write(lpszInfo,nLength) != nLength)
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
CNetStream & CNetStream::operator >> (unsigned char & val)
{
if (m_socket.Read(&val,sizeof(val)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
CNetStream & CNetStream::operator >> (unsigned short & val)
{
unsigned char buf[2];
if (m_socket.Read(buf,sizeof(buf)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
val = static_cast<unsigned char>(buf[0]) <<8 | buf[1];
return *this;
}
CNetStream & CNetStream::operator >> (unsigned long & val)
{
unsigned char buf[4];
if (m_socket.Read(buf,sizeof(buf)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
val = (static_cast<unsigned char>(buf[0]) << 24) |
(static_cast<unsigned char>(buf[1]) << 16) |
(static_cast<unsigned char>(buf[2]) << 8) |
static_cast<unsigned char>(buf[3]);
return *this;
}
CNetStream & CNetStream::operator >> (unsigned int & val)
{
unsigned char buf[4];
if (m_socket.Read(buf,sizeof(buf)) != static_cast<int>(sizeof(val)))
throw CExceptionBase(EIO,"Error to write a byte");
val = (static_cast<unsigned char>(buf[0]) << 24) |
(static_cast<unsigned char>(buf[1]) << 16) |
(static_cast<unsigned char>(buf[2]) << 8) |
static_cast<unsigned char>(buf[3]);
return *this;
}
CNetStream & CNetStream::operator >> (CUInt128& val)
{
unsigned char buf[16];
if (m_socket.Read(buf,sizeof(buf)) != static_cast<int>(sizeof(buf)))
throw CExceptionBase(EIO,"Error to write a byte");
return *this;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -