summaryrefslogtreecommitdiffstats
path: root/codec/SMPPBodyBase.st
blob: ea68753a2ca1a90a4fa48567420fb7cbbcfbf098 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"
 (C) 2014 by Holger Hans Peter Freyther
 All Rights Reserved

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
"

Osmo.TLVParserBase subclass: SMPPBodyBase [
    <comment: 'I represent a specific "BODY" of a Payload. My
sub-classes will provide the specific bodies.'>

    SMPPBodyBase class [
        genericNack [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000000
        ]

        bindReceiver [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000001
        ]

        bindReceiverResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000001
        ]

        bindTransmitter [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000002
        ]

        bindTransmitterResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000002
        ]

        querySM [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000003
        ]

        querySMResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000003
        ]

        submitSM [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000004

        ]

        submitSMResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000004
        ]

        deliverSM [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000005
        ]

        deliverSMResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000005
        ]

        unbind [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000006
        ]

        unbindResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000006
        ]

        replaceSM [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000007
        ]

        replaceSMResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000007
        ]

        cancelSM [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000008
        ]

        cancelSMResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000008
        ]

        bindTransceiver [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000009
        ]

        bindTransceiverResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000009
        ]

        outbind [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r0000000B
        ]

        enquireLink [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000015
        ]

        enquireLinkResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000015
        ]

        submitMulti [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000021
        ]

        submitMultiResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000021
        ]

        alertNotification [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000102
        ]

        dataSM [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r00000103
        ]

        dataSMResp [
            <category: '5.1.2.1 SMPP Command set'>
            ^16r80000103
        ]
    ]

    SMPPBodyBase class >> readFrom: aStream for: aHeader [
        <category: 'parsing'>

        self allSubclassesDo: [:each |
            aHeader commandId = each messageType
                ifTrue: [^each new readFrom: aStream]].

        ^self error: 'No handler for command id = %1' % aHeader commandId displayString.
    ]

    readFrom: aStream [
        | description |
        description := self class tlvDescription.
        description do: [:attribute |
            attribute isMandatory
                ifTrue: [self doParse: attribute stream: aStream].
            attribute isOptional
                ifTrue: [^self error: 'Optional attributes not implemented!'].
        ]
    ]

    writeOn: aMsg [
        <category: 'serialize'>
        "Custom write to avoid having to box String code"

        "Write each element"
        self class tlvDescription do: [:attr |
            | val |
            val := self instVarNamed: attr instVarName.

            "Now write it"
            val isNil ifFalse: [
                attr needsTag
                    ifTrue: [aMsg putByte: attr tag].
                attr parseClass write: val on: aMsg with: attr.
            ].
        ]
    ]
]