// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build darwin dragonfly freebsd netbsd openbsd

package route

// A Message represents a routing message.
type Message interface {
	// Sys returns operating system-specific information.
	Sys() []Sys
}

// A Sys reprensents operating system-specific information.
type Sys interface {
	// SysType returns a type of operating system-specific
	// information.
	SysType() SysType
}

// A SysType represents a type of operating system-specific
// information.
type SysType int

const (
	SysMetrics SysType = iota
	SysStats
)

// ParseRIB parses b as a routing information base and returns a list
// of routing messages.
func ( RIBType,  []byte) ([]Message, error) {
	if !.parseable() {
		return nil, errUnsupportedMessage
	}
	var  []Message
	,  := 0, 0
	for len() > 4 {
		++
		 := int(nativeEndian.Uint16([:2]))
		if  == 0 {
			return nil, errInvalidMessage
		}
		if len() <  {
			return nil, errMessageTooShort
		}
		if [2] != rtmVersion {
			 = [:]
			continue
		}
		if ,  := wireFormats[int([3])]; ! {
			++
		} else {
			,  := .parse(, )
			if  != nil {
				return nil, 
			}
			if  == nil {
				++
			} else {
				 = append(, )
			}
		}
		 = [:]
	}
	// We failed to parse any of the messages - version mismatch?
	if  != len()+ {
		return nil, errMessageMismatch
	}
	return , nil
}