// UnmarshalBinary unmarshals a raw byte slice into a Packet.
173427
func (p *Packet) UnmarshalBinary(b []byte) error {
	// Must have enough room to retrieve hardware address and IP lengths
	if len(b) < 8 {
		return io.ErrUnexpectedEOF
	}

	// Retrieve fixed length data

	p.HardwareType = binary.BigEndian.Uint16(b[0:2])
	p.ProtocolType = binary.BigEndian.Uint16(b[2:4])

	p.HardwareAddrLength = b[4]
	p.IPLength = b[5]

	p.Operation = Operation(binary.BigEndian.Uint16(b[6:8]))

	// Unmarshal variable length data at correct offset using lengths
	// defined by ml and il
	//
	// These variables are meant to improve readability of offset calculations
	// for the code below
	n := 8
	ml := int(p.HardwareAddrLength)
	ml2 := ml * 2
	il := int(p.IPLength)
	il2 := il * 2

	// Must have enough room to retrieve both hardware address and IP addresses
	addrl := n + ml2 + il2
	if len(b) < addrl {
		return io.ErrUnexpectedEOF
	}

	// Allocate single byte slice to store address information, which
	// is resliced into fields
	bb := make([]byte, addrl-n)

	// Sender hardware address
	copy(bb[0:ml], b[n:n+ml])
	p.SenderHardwareAddr = bb[0:ml]
	n += ml

	// Sender IP address
	copy(bb[ml:ml+il], b[n:n+il])
	p.SenderIP = bb[ml : ml+il]
	n += il

	// Target hardware address
	copy(bb[ml+il:ml2+il], b[n:n+ml])
	p.TargetHardwareAddr = bb[ml+il : ml2+il]
	n += ml

	// Target IP address
	copy(bb[ml2+il:ml2+il2], b[n:n+il])
	p.TargetIP = bb[ml2+il : ml2+il2]

	return nil
}
1297809
func (p *NewChannelReqPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 5 {
		return errors.New("lorawan: 5 bytes of data are expected")
	}
	p.ChIndex = data[0]
	p.MinDR = data[4] & ((1 << 3) ^ (1 << 2) ^ (1 << 1) ^ (1 << 0))
	p.MaxDR = (data[4] & ((1 << 7) ^ (1 << 6) ^ (1 << 5) ^ (1 << 4))) >> 4

	b := make([]byte, len(data))
	copy(b, data)
	b[4] = byte(0)
	p.Freq = binary.LittleEndian.Uint32(b[1:5]) * 100
	return nil
}
1243292
func (r *RelayMessageOption) UnmarshalBinary(b []byte) error {
	*r = make([]byte, len(b))
	copy(*r, b)
	return nil
}
1263313
func (p *ProprietaryMACCommandPayload) UnmarshalBinary(data []byte) error {
	p.Bytes = data
	return nil
}
502279
func (l *CFList) UnmarshalBinary(data []byte) error {
	if len(data) != 16 {
		return errors.New("lorawan: 16 bytes of data are expected")
	}

	l.CFListType = CFListType(data[15])

	switch l.CFListType {
	case CFListChannelMask:
		l.Payload = &CFListChannelMaskPayload{}
	default:
		l.Payload = &CFListChannelPayload{}
	}

	if err := l.Payload.UnmarshalBinary(false, data[:15]); err != nil {
		return err
	}

	return nil
}
1111605
func (o *GetAuthCallbackOKBody) UnmarshalBinary(b []byte) error {
	var res GetAuthCallbackOKBody
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*o = res
	return nil
}
97655
func (o *OptionCodes) UnmarshalBinary(p []byte) error {
	b := uio.NewBigEndianBuffer(p)
	*o = make(OptionCodes, 0, b.Len())
	for b.Has(1) {
		*o = append(*o, dhcp4.OptionCode(b.Read8()))
	}
	return b.FinError()
}
430944
func (v *VLAN) UnmarshalBinary(b []byte) error {
	// VLAN tag is always 2 bytes
	if len(b) != 2 {
		return io.ErrUnexpectedEOF
	}

	//  3 bits: priority
	//  1 bit : drop eligible
	// 12 bits: VLAN ID
	ub := binary.BigEndian.Uint16(b[0:2])
	v.Priority = Priority(uint8(ub >> 13))
	v.DropEligible = ub&0x1000 != 0
	v.ID = ub & 0x0fff

	// Check for VLAN ID in valid range
	if v.ID >= VLANMax {
		return ErrInvalidVLAN
	}

	return nil
}
170283
func (s *SubnetMask) UnmarshalBinary(p []byte) error {
	buf := uio.NewBigEndianBuffer(p)
	*s = buf.CopyN(net.IPv4len)
	return buf.FinError()
}
117683
func (rb *Bitmap) UnmarshalBinary(data []byte) error {
	var buf bytes.Buffer
	_, err := buf.Write(data)
	if err != nil {
		return err
	}
	reader := bufio.NewReader(&buf)
	_, err = rb.ReadFrom(reader)
	return err
}
951704
func (c *Cid) UnmarshalBinary(data []byte) error {
	casted, err := Cast(data)
	if err != nil {
		return err
	}
	c.str = casted.str
	return nil
}
1318159
func (p *DeviceTimeAnsPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 5 {
		return errors.New("lorawan: 5 bytes of data is expected")
	}

	seconds := binary.LittleEndian.Uint32(data[0:4])
	p.TimeSinceGPSEpoch = time.Second * time.Duration(seconds)
	p.TimeSinceGPSEpoch += time.Duration(data[4]) * 3906250

	return nil
}
167515
func (d *DHCPMessageType) UnmarshalBinary(p []byte) error {
	buf := uio.NewBigEndianBuffer(p)
	*d = DHCPMessageType(buf.Read8())
	return buf.FinError()
}
1354757
func (p *RXParamSetupAnsPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is expected")
	}
	p.ChannelACK = data[0]&(1<<0) > 0
	p.RX2DataRateACK = data[0]&(1<<1) > 0
	p.RX1DROffsetACK = data[0]&(1<<2) > 0
	return nil
}
100219
func (f *FileName) UnmarshalBinary(data []byte) error {
	buf := bytes.NewBuffer(data)

	_ = binary.Read(buf, binary.LittleEndian, &f.Length)

	f.Name = string(buf.Next(int(f.Length)))

	return nil
}
55333
func (p *Packet) UnmarshalBinary(q []byte) error {
	b := uio.NewBigEndianBuffer(q)

	p.Op = OpCode(b.Read8())
	p.HType = b.Read8()
	hlen := b.Read8()
	p.Hops = b.Read8()
	b.ReadBytes(p.TransactionID[:])
	p.Secs = b.Read16()

	flags := b.Read16()
	if flags&flagBroadcast != 0 {
		p.Broadcast = true
	}

	p.CIAddr = make(net.IP, net.IPv4len)
	b.ReadBytes(p.CIAddr)
	p.YIAddr = make(net.IP, net.IPv4len)
	b.ReadBytes(p.YIAddr)
	p.SIAddr = make(net.IP, net.IPv4len)
	b.ReadBytes(p.SIAddr)
	p.GIAddr = make(net.IP, net.IPv4len)
	b.ReadBytes(p.GIAddr)

	if hlen > chaddrLen {
		hlen = chaddrLen
	}
	// Always read 16 bytes, but only use hlen of them.
	p.CHAddr = make(net.HardwareAddr, chaddrLen)
	b.ReadBytes(p.CHAddr)
	p.CHAddr = p.CHAddr[:hlen]

	var sname [64]byte
	b.ReadBytes(sname[:])
	length := strings.Index(string(sname[:]), "\x00")
	if length == -1 {
		length = 64
	}
	p.ServerName = string(sname[:length])

	var file [128]byte
	b.ReadBytes(file[:])
	length = strings.Index(string(file[:]), "\x00")
	if length == -1 {
		length = 128
	}
	p.BootFile = string(file[:length])

	var cookie [4]byte
	b.ReadBytes(cookie[:])
	if cookie != magicCookie {
		return fmt.Errorf("malformed DHCP packet: got magic cookie %v, want %v", cookie[:], magicCookie[:])
	}

	if err := p.Options.Unmarshal(b); err != nil {
		return err
	}
	return b.FinError()
}
417911
func (k *AES128Key) UnmarshalBinary(data []byte) error {
	if len(data) != len(k) {
		return fmt.Errorf("lorawan: %d bytes of data are expected", len(k))
	}

	for i, v := range data {
		// little endian
		k[len(k)-i-1] = v
	}

	return nil
}