/
DownlinkDataServiceInformation.go
74 lines (62 loc) · 1.6 KB
/
DownlinkDataServiceInformation.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
package pfcpType
import (
"fmt"
"math/bits"
)
type DownlinkDataServiceInformation struct {
Qfii bool
Ppi bool
PagingPolicyIndicationValue uint8 // 0x00111111
Qfi uint8 // 0x00111111
}
func (d *DownlinkDataServiceInformation) MarshalBinary() (data []byte, err error) {
// Octet 5
tmpUint8 := btou(d.Qfii)<<1 | btou(d.Ppi)
data = append([]byte(""), tmpUint8)
// Octet m
if d.Ppi {
if bits.Len8(d.PagingPolicyIndicationValue) > 6 {
return []byte(""), fmt.Errorf("Paging policy information data shall not be greater than 6 bits binary integer")
}
data = append(data, d.PagingPolicyIndicationValue)
}
// Octet p
if d.Qfii {
if bits.Len8(d.Qfi) > 6 {
return []byte(""), fmt.Errorf("QFI shall not be greater than 6 bits binary integer")
}
data = append(data, d.Qfi)
}
return data, nil
}
func (d *DownlinkDataServiceInformation) UnmarshalBinary(data []byte) error {
length := uint16(len(data))
var idx uint16 = 0
// Octet 5
if length < idx+1 {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
d.Qfii = utob(data[idx] & BitMask2)
d.Ppi = utob(data[idx] & BitMask1)
idx = idx + 1
// Octet m
if d.Ppi {
if length < idx+1 {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
d.PagingPolicyIndicationValue = data[idx] & Mask6
idx = idx + 1
}
// Octet p
if d.Qfii {
if length < idx+1 {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
d.Qfi = data[idx] & Mask6
idx = idx + 1
}
if length != idx {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
return nil
}