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