diff options
author | Tom McPhail <tom.mcphail@icloud.com> | 2020-08-11 22:51:23 +1000 |
---|---|---|
committer | Tom McPhail <tom.mcphail@icloud.com> | 2020-08-13 21:10:11 +1000 |
commit | f84fcf45711e9c41d21faa408dc85fe73439f3cd (patch) | |
tree | 6bf292909ab9f9c7ef8a7fc8d94ffba014f911ff /dhcpv6/option_informationrefreshtime.go | |
parent | e10aec901335bf3bfea7ee5faf22cf0256f99420 (diff) |
Added structure, parsing and convenience fuctions for OptInformationRefreshTime (32) https://tools.ietf.org/html/rfc8415#section-21.23
Signed-off-by: Tom McPhail <tom.mcphail@icloud.com>
Diffstat (limited to 'dhcpv6/option_informationrefreshtime.go')
-rw-r--r-- | dhcpv6/option_informationrefreshtime.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/dhcpv6/option_informationrefreshtime.go b/dhcpv6/option_informationrefreshtime.go new file mode 100644 index 0000000..942d5c7 --- /dev/null +++ b/dhcpv6/option_informationrefreshtime.go @@ -0,0 +1,48 @@ +package dhcpv6 + +import ( + "fmt" + "time" + + "github.com/u-root/u-root/pkg/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("InformationRefreshTime: %v", op.InformationRefreshtime) +} + +// parseOptInformationRefreshTime builds an optInformationRefreshTime structure from a sequence +// of bytes. The input data does not include option code and length bytes. +func parseOptInformationRefreshTime(data []byte) (*optInformationRefreshTime, error) { + var opt optInformationRefreshTime + buf := uio.NewBigEndianBuffer(data) + + var irt Duration + irt.Unmarshal(buf) + opt.InformationRefreshtime = irt.Duration + return &opt, buf.FinError() +} |