Newer
Older
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
package packet
import (
"bytes"
"fmt"
)
// TerminationMessage represents a termination message
type TerminationMessage struct {
CommonHeader *CommonHeader
TLVs []*InformationTLV
}
// MsgType returns the type of this message
func (t *TerminationMessage) MsgType() uint8 {
return t.CommonHeader.MsgType
}
func decodeTerminationMessage(buf *bytes.Buffer, ch *CommonHeader) (*TerminationMessage, error) {
tm := &TerminationMessage{
TLVs: make([]*InformationTLV, 0, 2),
}
read := uint32(0)
toRead := ch.MsgLength - CommonHeaderLen
for read < toRead {
tlv, err := decodeInformationTLV(buf)
if err != nil {
return nil, fmt.Errorf("Unable to decode TLV: %v", err)
}
tm.TLVs = append(tm.TLVs, tlv)
read += uint32(tlv.InformationLength) + MinInformationTLVLen
}
return tm, nil
}