diff options
author | Christopher Koch <chrisko@google.com> | 2018-12-29 09:16:15 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-01-11 19:38:21 +0000 |
commit | 9492662dae0651fd4d6698d35b58ade7300e149e (patch) | |
tree | 77f53ebd6dfded05880c322005909b97a1cf140c /dhcpv4/option_vivc.go | |
parent | 512011c2eb80a7c0316405ef7aaae6e0b5b09b1c (diff) |
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.
Diffstat (limited to 'dhcpv4/option_vivc.go')
-rw-r--r-- | dhcpv4/option_vivc.go | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/dhcpv4/option_vivc.go b/dhcpv4/option_vivc.go index 4ff42a3..4c278e0 100644 --- a/dhcpv4/option_vivc.go +++ b/dhcpv4/option_vivc.go @@ -2,7 +2,6 @@ package dhcpv4 import ( "bytes" - "encoding/binary" "fmt" "github.com/u-root/u-root/pkg/uio" @@ -44,17 +43,13 @@ func (o *OptVIVC) Code() OptionCode { // ToBytes returns a serialized stream of bytes for this option. func (o *OptVIVC) ToBytes() []byte { - buf := make([]byte, o.Length()+2) - copy(buf[0:], []byte{byte(o.Code()), byte(o.Length())}) - - b := buf[2:] + buf := uio.NewBigEndianBuffer(nil) for _, id := range o.Identifiers { - binary.BigEndian.PutUint32(b[0:4], id.EntID) - b[4] = byte(len(id.Data)) - copy(b[5:], id.Data) - b = b[len(id.Data)+5:] + buf.Write32(id.EntID) + buf.Write8(uint8(len(id.Data))) + buf.WriteBytes(id.Data) } - return buf + return buf.Data() } // String returns a human-readable string for this option. |