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
39
package packet
import (
"bytes"
"fmt"
)
// InitiationMessage represents an initiation message
type InitiationMessage struct {
CommonHeader *CommonHeader
TLVs []*InformationTLV
}
// MsgType returns the type of this message
func (im *InitiationMessage) MsgType() uint8 {
return im.CommonHeader.MsgType
}
func decodeInitiationMessage(buf *bytes.Buffer, ch *CommonHeader) (Msg, error) {
im := &InitiationMessage{
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)
}
im.TLVs = append(im.TLVs, tlv)
read += uint32(tlv.InformationLength) + MinInformationTLVLen
fmt.Printf("read: %d\n", read)
}
return im, nil
}