summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_informationrefreshtime.go
blob: e0ba43c047cae80f650a11587075ab8eeb2a6b5a (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
42
43
44
45
46
47
package dhcpv6

import (
	"fmt"
	"time"

	"github.com/u-root/uio/uio"
)

// OptInformationRefreshTime implements OptionInformationRefreshTime option.
// https://tools.ietf.org/html/rfc8415#section-21.23
func OptInformationRefreshTime(irt time.Duration) *optInformationRefreshTime {
	return &optInformationRefreshTime{irt}
}

// optInformationRefreshTime represents an OptionInformationRefreshTime.
type optInformationRefreshTime struct {
	InformationRefreshtime time.Duration
}

// Code returns the option's code
func (op *optInformationRefreshTime) Code() OptionCode {
	return OptionInformationRefreshTime
}

// ToBytes serializes the option and returns it as a sequence of bytes
func (op *optInformationRefreshTime) ToBytes() []byte {
	buf := uio.NewBigEndianBuffer(nil)
	irt := Duration{op.InformationRefreshtime}
	irt.Marshal(buf)
	return buf.Data()
}

func (op *optInformationRefreshTime) String() string {
	return fmt.Sprintf("%s: %v", op.Code(), op.InformationRefreshtime)
}

// FromBytes builds an optInformationRefreshTime structure from a sequence of
// bytes. The input data does not include option code and length bytes.
func (op *optInformationRefreshTime) FromBytes(data []byte) error {
	buf := uio.NewBigEndianBuffer(data)

	var irt Duration
	irt.Unmarshal(buf)
	op.InformationRefreshtime = irt.Duration
	return buf.FinError()
}