diff options
Diffstat (limited to 'dhcpv4/option_generic.go')
-rw-r--r-- | dhcpv4/option_generic.go | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/dhcpv4/option_generic.go b/dhcpv4/option_generic.go index 264340c..a54cdeb 100644 --- a/dhcpv4/option_generic.go +++ b/dhcpv4/option_generic.go @@ -1,7 +1,6 @@ package dhcpv4 import ( - "errors" "fmt" ) @@ -9,22 +8,7 @@ import ( // data. Every option that does not have a specific implementation will fall // back to this option. type OptionGeneric struct { - OptionCode OptionCode - Data []byte -} - -// ParseOptionGeneric parses a bytestream and creates a new OptionGeneric from -// it, or an error. -func ParseOptionGeneric(code OptionCode, data []byte) (Option, error) { - if len(data) == 0 { - return nil, errors.New("invalid zero-length bytestream") - } - return &OptionGeneric{OptionCode: code, Data: data}, nil -} - -// Code returns the generic option code. -func (o OptionGeneric) Code() OptionCode { - return o.OptionCode + Data []byte } // ToBytes returns a serialized generic option as a slice of bytes. @@ -34,5 +18,10 @@ func (o OptionGeneric) ToBytes() []byte { // String returns a human-readable representation of a generic option. func (o OptionGeneric) String() string { - return fmt.Sprintf("%v -> %v", o.OptionCode.String(), o.Data) + return fmt.Sprintf("%v", o.Data) +} + +// OptGeneric returns a generic option. +func OptGeneric(code OptionCode, value []byte) Option { + return Option{Code: code, Value: OptionGeneric{value}} } |