-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrp_smma.go
67 lines (54 loc) · 1.34 KB
/
rp_smma.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
package sms
import (
"bytes"
"fmt"
)
// MemoryAvailable is RP-SMMA RPDU
type MemoryAvailable struct {
cpData
RMR byte `json:"rp-mr"` // M / Message Reference
}
// MarshalRP output byte data of this RPDU
func (d MemoryAvailable) MarshalRP() []byte {
return []byte{6, d.RMR}
}
// MarshalCP output byte data of this CPDU
func (d MemoryAvailable) MarshalCP() []byte {
return d.cpData.marshal(d.MarshalRP())
}
// UnmarshalMemoryAvailable decode MemoryAvailable MO from bytes
func UnmarshalMemoryAvailable(b []byte) (a MemoryAvailable, e error) {
e = a.UnmarshalRP(b)
return
}
// UnmarshalRP get data of this RPDU
func (d *MemoryAvailable) UnmarshalRP(b []byte) (e error) {
r := bytes.NewReader(b)
var tmp byte
if tmp, e = r.ReadByte(); e != nil {
return
}
if tmp != 6 {
e = UnexpectedMessageTypeError{
Expected: 6, Actual: b[0]}
return
}
if d.RMR, e = r.ReadByte(); e == nil && r.Len() != 0 {
e = ErrExtraData
}
return
}
// UnmarshalCP get data of this CPDU
func (d *MemoryAvailable) UnmarshalCP(b []byte) (e error) {
if b, e = d.cpData.unmarshal(b); e == nil {
e = d.UnmarshalRP(b)
}
return
}
func (d MemoryAvailable) String() string {
w := new(bytes.Buffer)
fmt.Fprintf(w, "RP-MemoryAvailable\n")
fmt.Fprintf(w, "%sCP-TI: %s\n", Indent, cpTIStat(d.TI))
fmt.Fprintf(w, "%sRP-MR: %d\n", Indent, d.RMR)
return w.String()
}