|
using System;
using System.Collections.Generic;
using System.Text;
namespace ProxyCommon
{
public class Header
{
#region Member Variables
private MessageType messageType;
private short senderEndPoint;
private short recieverEndPoint;
private int _contentSize;
#endregion
#region Constructor
public Header(MessageType MessageType, short SenderEndPoint, short RecieverEndPoint)
{
messageType = MessageType;
senderEndPoint = SenderEndPoint;
recieverEndPoint = RecieverEndPoint;
}
public Header(byte[] SerializationData)
{
messageType = (MessageType) SerializationData[0];
senderEndPoint = BitConverter.ToInt16(SerializationData, 1);
recieverEndPoint = BitConverter.ToInt16(SerializationData, 3);
_contentSize = BitConverter.ToInt32(SerializationData, 5);
}
#endregion
#region Properties
public short SenderEndPoint
{
get { return senderEndPoint; }
set { senderEndPoint = value; }
}
public short RecieverEndPoint
{
get { return recieverEndPoint; }
set { recieverEndPoint = value; }
}
public MessageType MessageType
{
get { return messageType; }
}
#endregion
#region Serialization
public virtual byte[] ToByteArray()
{
byte[] bytes = new byte[9];
bytes[0] = (byte)messageType;
BitConverter.GetBytes(senderEndPoint).CopyTo(bytes, 1);
BitConverter.GetBytes(recieverEndPoint).CopyTo(bytes, 3);
BitConverter.GetBytes(_contentSize).CopyTo(bytes, 5);
return bytes;
}
public int ContentSize
{
get { return _contentSize; }
set { _contentSize = value; }
}
public virtual int GetSize()
{
return 9;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.