summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp/bsdp_option_version.go
blob: d6b78c81cf40b140d9057e7980fd0f0f46779bae (plain)
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
package bsdp

import (
	"fmt"

	"github.com/insomniacslk/dhcp/dhcpv4"
	"github.com/u-root/u-root/pkg/uio"
)

// Version is the BSDP protocol version. Can be one of 1.0 or 1.1.
type Version [2]byte

// Specific versions.
var (
	Version1_0 = Version{1, 0}
	Version1_1 = Version{1, 1}
)

// ParseOptVersion constructs an OptVersion struct from a sequence of
// bytes and returns it, or an error.
func ParseOptVersion(data []byte) (Version, error) {
	buf := uio.NewBigEndianBuffer(data)
	var v Version
	buf.ReadBytes(v[:])
	return v, buf.FinError()
}

// Code returns the option code.
func (o Version) Code() dhcpv4.OptionCode {
	return OptionVersion
}

// ToBytes returns a serialized stream of bytes for this option.
func (o Version) ToBytes() []byte {
	return o[:]
}

// String returns a human-readable string for this option.
func (o Version) String() string {
	return fmt.Sprintf("BSDP Version -> %d.%d", o[0], o[1])
}