SmartOS/Message/MessageBase.cpp

43 lines
804 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "MessageBase.h"
// 初始化消息各字段为0
MessageBase::MessageBase()
{
Reply = false;
Error = false;
}
MessageBase::MessageBase(const MessageBase& msg)
{
Reply = msg.Reply;
Error = msg.Error;
}
bool MessageBase::ReadMessage(const Message& msg)
{
TS("MessageBase::ReadMessage");
Reply = msg.Reply > 0;
Error = msg.Error > 0;
//Stream ms(msg.Data, msg.Length);
auto ms = msg.ToStream();
return Read(ms);
}
void MessageBase::WriteMessage(Message& msg) const
{
TS("MessageBase::WriteMessage");
// 如果是令牌消息,这里就要自己小心了
//Stream ms(msg.Data, 256);
//MemoryStream ms;
auto ms = msg.ToStream();
Write(ms);
msg.Length = ms.Position();
//msg.SetData(Buffer(ms.GetBuffer(), ms.Position()));
}