-
Notifications
You must be signed in to change notification settings - Fork 38
/
pdu_submit_sm_resp.go
107 lines (80 loc) · 1.94 KB
/
pdu_submit_sm_resp.go
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
package smpp34
import (
"bytes"
)
var (
reqSSMRespFields = []string{MESSAGE_ID}
)
type SubmitSmResp struct {
*Header
mandatoryFields map[string]Field
tlvFields map[uint16]*TLVField
}
func NewSubmitSmResp(hdr *Header, b []byte) (*SubmitSmResp, error) {
r := bytes.NewBuffer(b)
fields, _, err := create_pdu_fields(reqSSMRespFields, r)
if err != nil {
return nil, err
}
s := &SubmitSmResp{Header: hdr, mandatoryFields: fields}
return s, nil
}
func (s *SubmitSmResp) GetField(f string) Field {
return s.mandatoryFields[f]
}
func (s *SubmitSmResp) Fields() map[string]Field {
return s.mandatoryFields
}
func (s *SubmitSmResp) MandatoryFieldsList() []string {
return reqSSMRespFields
}
func (s *SubmitSmResp) Ok() bool {
if s.Header.Status == ESME_ROK {
return true
}
return false
}
func (s *SubmitSmResp) GetHeader() *Header {
return s.Header
}
func (s *SubmitSmResp) SetField(f string, v interface{}) error {
if s.validate_field(f, v) {
field := NewField(f, v)
if field != nil {
s.mandatoryFields[f] = field
return nil
}
}
return FieldValueErr
}
func (s *SubmitSmResp) SetSeqNum(i uint32) {
s.Header.Sequence = i
}
func (s *SubmitSmResp) SetTLVField(t, l int, v []byte) error {
return TLVFieldPduErr
}
func (s *SubmitSmResp) validate_field(f string, v interface{}) bool {
if included_check(s.MandatoryFieldsList(), f) && validate_pdu_field(f, v) {
return true
}
return false
}
func (s *SubmitSmResp) TLVFields() map[uint16]*TLVField {
return s.tlvFields
}
func (s *SubmitSmResp) writeFields() []byte {
b := []byte{}
for _, i := range s.MandatoryFieldsList() {
v := s.mandatoryFields[i].ByteArray()
b = append(b, v...)
}
return b
}
func (s *SubmitSmResp) Writer() []byte {
b := s.writeFields()
h := packUi32(uint32(len(b) + 16))
h = append(h, packUi32(uint32(SUBMIT_SM_RESP))...)
h = append(h, packUi32(uint32(s.Header.Status))...)
h = append(h, packUi32(s.Header.Sequence)...)
return append(h, b...)
}