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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/**
 * This class file was automatically generated by jASN1 v1.9.0 (http://www.openmuc.org)
 */
 
package org.openmuc.openiec61850.internal.mms.asn1;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
 
import org.openmuc.jasn1.ber.BerTag;
import org.openmuc.jasn1.ber.ReverseByteArrayOutputStream;
 
public class MMSpdu implements Serializable {
 
    private static final long serialVersionUID = 1L;
 
    public byte[] code = null;
    private ConfirmedRequestPDU confirmedRequestPDU = null;
    private ConfirmedResponsePDU confirmedResponsePDU = null;
    private ConfirmedErrorPDU confirmedErrorPDU = null;
    private UnconfirmedPDU unconfirmedPDU = null;
    private RejectPDU rejectPDU = null;
    private InitiateRequestPDU initiateRequestPDU = null;
    private InitiateResponsePDU initiateResponsePDU = null;
    private InitiateErrorPDU initiateErrorPDU = null;
    private ConcludeRequestPDU concludeRequestPDU = null;
 
    public MMSpdu() {
    }
 
    public MMSpdu(byte[] code) {
        this.code = code;
    }
 
    public void setConfirmedRequestPDU(ConfirmedRequestPDU confirmedRequestPDU) {
        this.confirmedRequestPDU = confirmedRequestPDU;
    }
 
    public ConfirmedRequestPDU getConfirmedRequestPDU() {
        return confirmedRequestPDU;
    }
 
    public void setConfirmedResponsePDU(ConfirmedResponsePDU confirmedResponsePDU) {
        this.confirmedResponsePDU = confirmedResponsePDU;
    }
 
    public ConfirmedResponsePDU getConfirmedResponsePDU() {
        return confirmedResponsePDU;
    }
 
    public void setConfirmedErrorPDU(ConfirmedErrorPDU confirmedErrorPDU) {
        this.confirmedErrorPDU = confirmedErrorPDU;
    }
 
    public ConfirmedErrorPDU getConfirmedErrorPDU() {
        return confirmedErrorPDU;
    }
 
    public void setUnconfirmedPDU(UnconfirmedPDU unconfirmedPDU) {
        this.unconfirmedPDU = unconfirmedPDU;
    }
 
    public UnconfirmedPDU getUnconfirmedPDU() {
        return unconfirmedPDU;
    }
 
    public void setRejectPDU(RejectPDU rejectPDU) {
        this.rejectPDU = rejectPDU;
    }
 
    public RejectPDU getRejectPDU() {
        return rejectPDU;
    }
 
    public void setInitiateRequestPDU(InitiateRequestPDU initiateRequestPDU) {
        this.initiateRequestPDU = initiateRequestPDU;
    }
 
    public InitiateRequestPDU getInitiateRequestPDU() {
        return initiateRequestPDU;
    }
 
    public void setInitiateResponsePDU(InitiateResponsePDU initiateResponsePDU) {
        this.initiateResponsePDU = initiateResponsePDU;
    }
 
    public InitiateResponsePDU getInitiateResponsePDU() {
        return initiateResponsePDU;
    }
 
    public void setInitiateErrorPDU(InitiateErrorPDU initiateErrorPDU) {
        this.initiateErrorPDU = initiateErrorPDU;
    }
 
    public InitiateErrorPDU getInitiateErrorPDU() {
        return initiateErrorPDU;
    }
 
    public void setConcludeRequestPDU(ConcludeRequestPDU concludeRequestPDU) {
        this.concludeRequestPDU = concludeRequestPDU;
    }
 
    public ConcludeRequestPDU getConcludeRequestPDU() {
        return concludeRequestPDU;
    }
 
    public int encode(OutputStream os) throws IOException {
 
        if (code != null) {
            for (int i = code.length - 1; i >= 0; i--) {
                os.write(code[i]);
            }
            return code.length;
        }
 
        int codeLength = 0;
        if (concludeRequestPDU != null) {
            codeLength += concludeRequestPDU.encode(os, false);
            // write tag: CONTEXT_CLASS, PRIMITIVE, 11
            os.write(0x8B);
            codeLength += 1;
            return codeLength;
        }
 
        if (initiateErrorPDU != null) {
            codeLength += initiateErrorPDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 10
            os.write(0xAA);
            codeLength += 1;
            return codeLength;
        }
 
        if (initiateResponsePDU != null) {
            codeLength += initiateResponsePDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 9
            os.write(0xA9);
            codeLength += 1;
            return codeLength;
        }
 
        if (initiateRequestPDU != null) {
            codeLength += initiateRequestPDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 8
            os.write(0xA8);
            codeLength += 1;
            return codeLength;
        }
 
        if (rejectPDU != null) {
            codeLength += rejectPDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 4
            os.write(0xA4);
            codeLength += 1;
            return codeLength;
        }
 
        if (unconfirmedPDU != null) {
            codeLength += unconfirmedPDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 3
            os.write(0xA3);
            codeLength += 1;
            return codeLength;
        }
 
        if (confirmedErrorPDU != null) {
            codeLength += confirmedErrorPDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
            os.write(0xA2);
            codeLength += 1;
            return codeLength;
        }
 
        if (confirmedResponsePDU != null) {
            codeLength += confirmedResponsePDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
            os.write(0xA1);
            codeLength += 1;
            return codeLength;
        }
 
        if (confirmedRequestPDU != null) {
            codeLength += confirmedRequestPDU.encode(os, false);
            // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
            os.write(0xA0);
            codeLength += 1;
            return codeLength;
        }
 
        throw new IOException("Error encoding CHOICE: No element of CHOICE was selected.");
    }
 
    public int decode(InputStream is) throws IOException {
        return decode(is, null);
    }
 
    public int decode(InputStream is, BerTag berTag) throws IOException {
 
        int codeLength = 0;
        BerTag passedTag = berTag;
 
        if (berTag == null) {
            berTag = new BerTag();
            codeLength += berTag.decode(is);
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
            confirmedRequestPDU = new ConfirmedRequestPDU();
            codeLength += confirmedRequestPDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
            confirmedResponsePDU = new ConfirmedResponsePDU();
            codeLength += confirmedResponsePDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
            confirmedErrorPDU = new ConfirmedErrorPDU();
            codeLength += confirmedErrorPDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) {
            unconfirmedPDU = new UnconfirmedPDU();
            codeLength += unconfirmedPDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) {
            rejectPDU = new RejectPDU();
            codeLength += rejectPDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) {
            initiateRequestPDU = new InitiateRequestPDU();
            codeLength += initiateRequestPDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) {
            initiateResponsePDU = new InitiateResponsePDU();
            codeLength += initiateResponsePDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 10)) {
            initiateErrorPDU = new InitiateErrorPDU();
            codeLength += initiateErrorPDU.decode(is, false);
            return codeLength;
        }
 
        if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 11)) {
            concludeRequestPDU = new ConcludeRequestPDU();
            codeLength += concludeRequestPDU.decode(is, false);
            return codeLength;
        }
 
        if (passedTag != null) {
            return 0;
        }
 
        throw new IOException("Error decoding CHOICE: Tag " + berTag + " matched to no item.");
    }
 
    public void encodeAndSave(int encodingSizeGuess) throws IOException {
        ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess);
        encode(os);
        code = os.getArray();
    }
 
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        appendAsString(sb, 0);
        return sb.toString();
    }
 
    public void appendAsString(StringBuilder sb, int indentLevel) {
 
        if (confirmedRequestPDU != null) {
            sb.append("confirmedRequestPDU: ");
            confirmedRequestPDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (confirmedResponsePDU != null) {
            sb.append("confirmedResponsePDU: ");
            confirmedResponsePDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (confirmedErrorPDU != null) {
            sb.append("confirmedErrorPDU: ");
            confirmedErrorPDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (unconfirmedPDU != null) {
            sb.append("unconfirmedPDU: ");
            unconfirmedPDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (rejectPDU != null) {
            sb.append("rejectPDU: ");
            rejectPDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (initiateRequestPDU != null) {
            sb.append("initiateRequestPDU: ");
            initiateRequestPDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (initiateResponsePDU != null) {
            sb.append("initiateResponsePDU: ");
            initiateResponsePDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (initiateErrorPDU != null) {
            sb.append("initiateErrorPDU: ");
            initiateErrorPDU.appendAsString(sb, indentLevel + 1);
            return;
        }
 
        if (concludeRequestPDU != null) {
            sb.append("concludeRequestPDU: ").append(concludeRequestPDU);
            return;
        }
 
        sb.append("<none>");
    }
 
}