-
Notifications
You must be signed in to change notification settings - Fork 0
/
segmented_info.go
82 lines (67 loc) · 1.57 KB
/
segmented_info.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
package zkm
type SegmentedInfo struct {
Part int
TotalParts int
Id int
}
func NewSegmentedInfo(pdu *Pdu) *SegmentedInfo {
segmentedInfo := &SegmentedInfo{Part: 1, TotalParts: 1, Id: 0}
esmClass, err := pdu.GetMainAsUint32(ESMClass)
if err != nil {
return segmentedInfo
}
if (esmClass & 0x40) != 0 {
sm, err := pdu.GetMainAsRaw(ShortMessage)
smLength := len(sm)
if err != nil || smLength == 0 {
return segmentedInfo
}
udhl := int(sm[0]) + 1
if smLength < udhl {
udhl = smLength
}
for i := 1; i < udhl; {
iei := int(sm[i])
i++
iel := int(sm[i])
i++
switch iei {
case 0x00: //concat 8bit
if iel == 3 {
segmentedInfo.Id = int(sm[i])
i++
segmentedInfo.TotalParts = int(sm[i])
i++
segmentedInfo.Part = int(sm[i])
i++
return segmentedInfo
}
case 0x08: //concat 16bit
if iel == 4 {
segmentedInfo.Id = (int(sm[i]) << 8) | (int(sm[i+1]))
i += 2
segmentedInfo.TotalParts = int(sm[i])
i++
segmentedInfo.Part = int(sm[i])
i++
return segmentedInfo
}
default:
i += iel
}
}
} else if sarTotalSegments, err := pdu.GetOptAsUint32(TagSarTotalSegments); err == nil {
sarMsgRefNum, err := pdu.GetOptAsUint32(TagSarMsgRefNum)
if err != nil {
return segmentedInfo
}
sarSegmentSeqnum, err := pdu.GetOptAsUint32(TagSarSegmentSeqnum)
if err != nil {
return segmentedInfo
}
segmentedInfo.Id = int(sarMsgRefNum)
segmentedInfo.TotalParts = int(sarTotalSegments)
segmentedInfo.Part = int(sarSegmentSeqnum)
}
return segmentedInfo
}