From 9492662dae0651fd4d6698d35b58ade7300e149e Mon Sep 17 00:00:00 2001 From: Christopher Koch Date: Sat, 29 Dec 2018 09:16:15 -0800 Subject: dhcpv4: simplify marshaling options to binary. - Consolidate writing the option code and length to Options.Marshal rather than doing it in each individual option. - Use uio in marshaling code. --- dhcpv4/option_userclass.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'dhcpv4/option_userclass.go') diff --git a/dhcpv4/option_userclass.go b/dhcpv4/option_userclass.go index 44ce090..560d6ac 100644 --- a/dhcpv4/option_userclass.go +++ b/dhcpv4/option_userclass.go @@ -24,15 +24,16 @@ func (op *OptUserClass) Code() OptionCode { // ToBytes serializes the option and returns it as a sequence of bytes func (op *OptUserClass) ToBytes() []byte { - buf := []byte{byte(op.Code()), byte(op.Length())} + buf := uio.NewBigEndianBuffer(nil) if !op.Rfc3004 { - return append(buf, op.UserClasses[0]...) - } - for _, uc := range op.UserClasses { - buf = append(buf, byte(len(uc))) - buf = append(buf, uc...) + buf.WriteBytes(op.UserClasses[0]) + } else { + for _, uc := range op.UserClasses { + buf.Write8(uint8(len(uc))) + buf.WriteBytes(uc) + } } - return buf + return buf.Data() } // Length returns the option length -- cgit v1.2.3