forked from free5gc/pfcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplyAction.go
47 lines (39 loc) · 861 Bytes
/
ApplyAction.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
package pfcpType
import (
"fmt"
)
type ApplyAction struct {
Dupl bool
Nocp bool
Buff bool
Forw bool
Drop bool
}
func (a *ApplyAction) MarshalBinary() (data []byte, err error) {
// Octet 5
tmpUint8 := btou(a.Dupl)<<4 |
btou(a.Nocp)<<3 |
btou(a.Buff)<<2 |
btou(a.Forw)<<1 |
btou(a.Drop)
data = append([]byte(""), tmpUint8)
return data, nil
}
func (a *ApplyAction) 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)
}
a.Dupl = utob(data[idx] & BitMask5)
a.Nocp = utob(data[idx] & BitMask4)
a.Buff = utob(data[idx] & BitMask3)
a.Forw = utob(data[idx] & BitMask2)
a.Drop = utob(data[idx] & BitMask1)
idx = idx + 1
if length != idx {
return fmt.Errorf("Inadequate TLV length: %d", length)
}
return nil
}