增加SetError

This commit is contained in:
nnhy 2015-09-09 07:49:45 +00:00
parent add9e693f7
commit 4c50baec42
2 changed files with 28 additions and 2 deletions

View File

@ -30,6 +30,24 @@ void Message::SetData(const ByteArray& bs, uint offset)
if(Length > 0 && bs.GetBuffer() != Data + offset) bs.CopyTo(Data + offset, Length);
}
void Message::SetError(byte errorCode, const char* msg)
{
/*byte* p = Data;
*p++ = errorCode;
while(msg) *p++ = (byte)*msg++;
Length = p - Data;*/
Error = true;
Stream ms(Data, MaxDataSize());
ms.Write(errorCode);
ms.Write(msg);
Length = ms.Position();
}
bool Message::Clone(const Message& msg)
{
Stream ms;
@ -43,12 +61,18 @@ bool Message::Clone(const Message& msg)
// 负载数据转数据流
Stream Message::ToStream()
{
return Stream(Data, MaxDataSize());
Stream ms(Data, MaxDataSize());
ms.Length = Length;
return ms;
}
Stream Message::ToStream() const
{
return Stream((const byte*)Data, MaxDataSize());
Stream ms((const byte*)Data, MaxDataSize());
ms.Length = Length;
return ms;
}
/*// 负载数据转字节数组

View File

@ -37,6 +37,8 @@ public:
// 设置数据
void SetData(const byte* buf, uint len, uint offset = 0);
void SetData(const ByteArray& bs, uint offset = 0);
void SetError(byte errorCode, const char* msg = NULL);
// 负载数据转数据流
Stream ToStream();
Stream ToStream() const;