Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SmppPduQuerySm.cs « SmppServerLib - github.com/ClusterM/smpp-sharp-lib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aee5b734b3aad97b816f735f872b454fb92414bd (plain)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Flex.Cluster.Smpp
{
    public class SmppPduQuerySm : SmppPdu
    {
        uint offsetMessageId, offsetSourceAddrTon, offsetSourceAddrNpi, offsetSourceAddr;

        public string MessageId
        {
            get { return ReadCString(offsetMessageId); }
        }
        public byte SourceAddrTon
        {
            get { return ReadByte(offsetSourceAddrTon); }
        }
        public byte SourceAddrNpi
        {
            get { return ReadByte(offsetSourceAddrNpi); }
        }
        public string SourceAddr
        {
            get { return ReadCString(offsetSourceAddr); }
        }
        
        public SmppPduQuerySm(string messageId, byte sourceAddrTon, byte sourceAddrNpi, string sourceAddr)
            : base(SmppCommandType.query_sm)
        {
            if (messageId.Length > 64) throw new ArgumentOutOfRangeException("messageId");
            offsetMessageId = CurrentOffset;
            WriteCString(messageId);

            offsetSourceAddrTon = CurrentOffset;
            WriteByte(sourceAddrTon);

            offsetSourceAddrNpi = CurrentOffset;
            WriteByte(sourceAddrNpi);

            if (sourceAddr.Length > 20) throw new ArgumentOutOfRangeException("sourceAddr");
            offsetSourceAddr = CurrentOffset;
            WriteCString(sourceAddr);
        }

        public SmppPduQuerySm(byte[] bytes) : this(bytes, (uint)bytes.Length) { }
        public SmppPduQuerySm(byte[] bytes, uint length)
            : base(bytes, length)
        {
            if (CommandId != SmppCommandType.query_sm) throw new Exception("Invaid command ID");
            offsetMessageId = 12;
            offsetSourceAddrTon = FindCStringEnd(offsetMessageId);
            offsetSourceAddrNpi = offsetSourceAddrTon + 1;
            offsetSourceAddr = offsetSourceAddrNpi + 1;
        }
    }
}