forked from free5gc/pfcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GateStatus.go
49 lines (37 loc) · 911 Bytes
/
GateStatus.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
package pfcpType
import (
"bytes"
"encoding/binary"
"fmt"
)
const (
GateOpen uint8 = iota
GateClose
)
type GateStatus struct {
ULGate uint8 // 0x00001100
DLGate uint8 // 0x00000011
}
func (g *GateStatus) MarshalBinary() ([]byte, error) {
buf := &bytes.Buffer{}
if g.ULGate > 1 {
return nil, fmt.Errorf("UL Gate shall be 0 or 1")
}
if g.DLGate > 1 {
return nil, fmt.Errorf("DL Gate shall be 0 or 1")
}
if err := buf.WriteByte(g.ULGate<<2 | g.DLGate); err != nil {
return nil, fmt.Errorf("marshal UL & DL Gate fail: " + err.Error())
}
return buf.Bytes(), nil
}
func (g *GateStatus) UnmarshalBinary(data []byte) error {
buf := bytes.NewBuffer(data)
var tmpByte byte
if err := binary.Read(buf, binary.BigEndian, &tmpByte); err != nil {
return fmt.Errorf("unmarshal UL & DL Gate fail: " + err.Error())
}
g.ULGate = (tmpByte >> 2) & 0x3
g.DLGate = tmpByte & 0x3
return nil
}