forked from free5gc/pfcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DroppedDLTrafficThreshold.go
73 lines (61 loc) · 1.54 KB
/
DroppedDLTrafficThreshold.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
package pfcpType
import (
"encoding/binary"
"fmt"
)
type DroppedDLTrafficThreshold struct {
Dlby bool
Dlpa bool
DownlinkPackets uint64
NumberOfBytesOfDownlinkData uint64
}
func (d *DroppedDLTrafficThreshold) MarshalBinary() (data []byte, err error) {
var idx uint16 = 0
// Octet 5
tmpUint8 := btou(d.Dlby)<<1 | btou(d.Dlpa)
data = append([]byte(""), tmpUint8)
idx = idx + 1
// Octet m to (m+7)
if d.Dlpa {
data = append(data, make([]byte, 8)...)
binary.BigEndian.PutUint64(data[idx:], d.DownlinkPackets)
idx = idx + 8
}
// Octet o to (o+7)
if d.Dlby {
data = append(data, make([]byte, 8)...)
binary.BigEndian.PutUint64(data[idx:], d.NumberOfBytesOfDownlinkData)
}
return data, nil
}
func (d *DroppedDLTrafficThreshold) 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.Dlby = utob(data[idx] & BitMask2)
d.Dlpa = utob(data[idx] & BitMask1)
idx = idx + 1
// Octet m to (m+7)
if d.Dlpa {
if length < idx+8 {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
d.DownlinkPackets = binary.BigEndian.Uint64(data[idx:])
idx = idx + 8
}
// Octet o to (o+7)
if d.Dlby {
if length < idx+8 {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
d.NumberOfBytesOfDownlinkData = binary.BigEndian.Uint64(data[idx:])
idx = idx + 8
}
if length != idx {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
return nil
}