Renamed MakePacket to Unmarshal and MakeOptions to UnmarshalOptions

This commit is contained in:
Dmitri Dolguikh 2018-01-03 14:29:30 -08:00 committed by Dave Anderson
parent 09440c6b84
commit a0fc6b6e06
4 changed files with 7 additions and 7 deletions

View File

@ -98,7 +98,7 @@ func (c *Conn) RecvDHCP() (*Packet, net.IP, error) {
if !rcm.Dst.IsMulticast() || !rcm.Dst.Equal(c.group) {
continue // unknown group, discard
}
pkt, err := MakePacket(b, n)
pkt, err := Unmarshal(b, n)
if err != nil {
return nil, nil, err
}

View File

@ -72,8 +72,8 @@ func MakeOption(id uint16, value []byte) *Option {
// Options contains all options of a DHCPv6 packet
type Options map[uint16][]*Option
// MakeOptions unmarshals individual Options and returns them in a new Options data structure
func MakeOptions(bs []byte) (Options, error) {
// UnmarshalOptions unmarshals individual Options and returns them in a new Options data structure
func UnmarshalOptions(bs []byte) (Options, error) {
ret := make(Options)
for len(bs) > 0 {
o, err := UnmarshalOption(bs)

View File

@ -98,7 +98,7 @@ func TestMakeStatusOption(t *testing.T) {
func TestUnmarshalFailsIfOROLengthIsOdd(t *testing.T) {
in := []byte{0, 6, 0, 3, 0, 1, 1}
if _, err := MakeOptions(in); err == nil {
if _, err := UnmarshalOptions(in); err == nil {
t.Fatalf("Parsing options should fail: option request for options has odd length.")
}
}

View File

@ -32,9 +32,9 @@ type Packet struct {
Options Options
}
// MakePacket creates a Packet out of its serialized representation
func MakePacket(bs []byte, packetLength int) (*Packet, error) {
options, err := MakeOptions(bs[4:packetLength])
// Unmarshal creates a Packet out of its serialized representation
func Unmarshal(bs []byte, packetLength int) (*Packet, error) {
options, err := UnmarshalOptions(bs[4:packetLength])
if err != nil {
return nil, fmt.Errorf("packet has malformed options section: %s", err)
}