namespace AsiaINFO.SMS.CMPP2 { using System; public class MessageHeader { private CMPP_Command_Id _Command_Id; private uint _Sequence_Id; private uint _Total_Length; public const int Length = 12; public MessageHeader(byte[] bytes) { byte[] dst = new byte[4]; Buffer.BlockCopy(bytes, 0, dst, 0, dst.Length); Array.Reverse(dst); this._Total_Length = BitConverter.ToUInt32(dst, 0); Buffer.BlockCopy(bytes, 4, dst, 0, dst.Length); Array.Reverse(dst); this._Command_Id = (CMPP_Command_Id) BitConverter.ToUInt32(dst, 0); Buffer.BlockCopy(bytes, 8, dst, 0, dst.Length); Array.Reverse(dst); this._Sequence_Id = BitConverter.ToUInt32(dst, 0); } public MessageHeader(uint Total_Length, CMPP_Command_Id Command_Id, uint Sequence_Id) { this._Total_Length = Total_Length; this._Command_Id = Command_Id; this._Sequence_Id = Sequence_Id; } public byte[] ToBytes() { byte[] dst = new byte[12]; byte[] bytes = BitConverter.GetBytes(this._Total_Length); Array.Reverse(bytes); Buffer.BlockCopy(bytes, 0, dst, 0, 4); bytes = BitConverter.GetBytes((uint) this._Command_Id); Array.Reverse(bytes); Buffer.BlockCopy(bytes, 0, dst, 4, 4); bytes = BitConverter.GetBytes(this._Sequence_Id); Array.Reverse(bytes); Buffer.BlockCopy(bytes, 0, dst, 8, 4); return dst; } public override string ToString() { return string.Format("MessageHeader: tCommand_Id={0} tSequence_Id={1} tTotal_Length={2}", this._Command_Id, this._Sequence_Id, this._Total_Length); } public CMPP_Command_Id Command_Id { get { return this._Command_Id; } } public uint Sequence_Id { get { return this._Sequence_Id; } } public uint Total_Length { get { return this._Total_Length; } } } }