prepare SubTLV handling in PacketDecoder
This commit is contained in:
parent
b110db1f5e
commit
9bc7c59221
2
main.go
2
main.go
|
@ -90,7 +90,6 @@ func run(opt options) error {
|
|||
var s tlv.PacketDecoder
|
||||
s.Reset(b, src)
|
||||
for s.Scan() {
|
||||
var subtlv []byte
|
||||
switch t := s.TLV().(type) {
|
||||
case tlv.NextHop:
|
||||
fmt.Printf("%12s %s\n", t.T(), t.Address)
|
||||
|
@ -122,6 +121,7 @@ func run(opt options) error {
|
|||
fmt.Println("got nil TLV")
|
||||
}
|
||||
}
|
||||
subtlv := s.SubTLV()
|
||||
for len(subtlv) > 0 {
|
||||
switch tlv.SubType(subtlv[0]) {
|
||||
case tlv.SubTypeSourcePrefix:
|
||||
|
|
10
tlv/tlv.go
10
tlv/tlv.go
|
@ -36,6 +36,10 @@ type TLV interface {
|
|||
|
||||
type SubType uint8
|
||||
|
||||
func (s SubType) IsMandatory() bool {
|
||||
return s >= 128
|
||||
}
|
||||
|
||||
const (
|
||||
SubTypePad1 = SubType(0)
|
||||
SubTypePadN = SubType(1)
|
||||
|
@ -244,6 +248,12 @@ func (s *PacketDecoder) TLV() TLV {
|
|||
}
|
||||
return s.tlv
|
||||
}
|
||||
func (s *PacketDecoder) SubTLV() []byte {
|
||||
if s.err != nil {
|
||||
return nil
|
||||
}
|
||||
return s.subtlv
|
||||
}
|
||||
func (s *PacketDecoder) Err() error {
|
||||
return s.err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue