wzp
2021-07-28 864986e4cad03f6b9bba9a7e65379db496b62a6a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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;
            }
        }
    }
}