forked from CodeMonkeyKevin/smpp34
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdu_query_sm_resp.go
117 lines (92 loc) · 2.16 KB
/
pdu_query_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
108
109
110
111
112
113
114
115
116
117
package smpp34
import (
"bytes"
"encoding/binary"
)
var (
// Required QuerySmResp Fields
reqQSMRespFields = []string{
MESSAGE_ID,
FINAL_DATE,
MESSAGE_STATE,
ERROR_CODE,
}
)
type QuerySmResp struct {
*Header
mandatoryFields map[string]Field
tlvFields map[uint16]*TLVField
}
func NewQuerySmResp(hdr *Header, b []byte) (*QuerySmResp, error) {
r := bytes.NewBuffer(b)
fields, _, err := create_pdu_fields(reqQSMRespFields, r)
if err != nil {
return nil, err
}
s := &QuerySmResp{Header: hdr, mandatoryFields: fields}
return s, nil
}
func (s *QuerySmResp) GetField(f string) Field {
switch f {
case MESSAGE_STATE, ERROR_CODE:
var v uint8
binary.Read(bytes.NewBuffer(s.mandatoryFields[f].ByteArray()),
binary.BigEndian, &v)
return NewFixedField(v)
default:
return s.mandatoryFields[f]
}
}
func (s *QuerySmResp) Fields() map[string]Field {
return s.mandatoryFields
}
func (s *QuerySmResp) MandatoryFieldsList() []string {
return reqQSMRespFields
}
func (s *QuerySmResp) Ok() bool {
return true
}
func (s *QuerySmResp) GetHeader() *Header {
return s.Header
}
func (s *QuerySmResp) 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 *QuerySmResp) SetSeqNum(i uint32) {
s.Header.Sequence = i
}
func (s *QuerySmResp) SetTLVField(t, l int, v []byte) error {
return TLVFieldPduErr
}
func (s *QuerySmResp) validate_field(f string, v interface{}) bool {
if included_check(s.MandatoryFieldsList(), f) && validate_pdu_field(f, v) {
return true
}
return false
}
func (s *QuerySmResp) TLVFields() map[uint16]*TLVField {
return s.tlvFields
}
func (s *QuerySmResp) writeFields() []byte {
b := []byte{}
for _, i := range s.MandatoryFieldsList() {
v := s.mandatoryFields[i].ByteArray()
b = append(b, v...)
}
return b
}
func (s *QuerySmResp) Writer() []byte {
b := s.writeFields()
h := packUi32(uint32(len(b) + 16))
h = append(h, packUi32(uint32(s.Header.Id))...)
h = append(h, packUi32(uint32(s.Header.Status))...)
h = append(h, packUi32(s.Header.Sequence)...)
return append(h, b...)
}