// UnmarshalBinary unmarshals a byte slice into a VLAN.
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
}
513996
func (r *ServiceConfigResponse) UnmarshalBinary(data []byte) error {
	dec := codec.NewDecoderBytes(data, msgpackHandle)

	type Alias ServiceConfigResponse
	var a Alias

	if err := dec.Decode(&a); err != nil {
		return err
	}

	*r = ServiceConfigResponse(a)

	var err error

	// Fix strings and maps in the returned maps
	r.ProxyConfig, err = lib.MapWalk(r.ProxyConfig)
	if err != nil {
		return err
	}
	for k := range r.UpstreamConfigs {
		r.UpstreamConfigs[k], err = lib.MapWalk(r.UpstreamConfigs[k])
		if err != nil {
			return err
		}
	}
	return nil
}
1139690
func (p *TXParamSetupReqPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is expected")
	}

	if data[0]&(1<<4) > 0 {
		p.UplinkDwellTime = DwellTime400ms
	}
	if data[0]&(1<<5) > 0 {
		p.DownlinkDwelltime = DwellTime400ms
	}
	p.MaxEIRP = []uint8{8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36}[data[0]&15]

	return nil
}
826937
func (p *NewChannelAnsPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is expected")
	}
	p.ChannelFrequencyOK = data[0]&(1<<0) > 0
	p.DataRateRangeOK = data[0]&(1<<1) > 0
	return nil
}
325760
func (u *URL) UnmarshalBinary(b []byte) error {
	uu, err := url.Parse(string(b))
	if err != nil {
		return err
	}

	*u = URL(*uu)
	return nil
}
955201
func (p *ResetConfPayload) UnmarshalBinary(data []byte) error {
	return p.ServLoRaWANVersion.UnmarshalBinary(data)
}
921581
func (p *RekeyConfPayload) UnmarshalBinary(data []byte) error {
	return p.ServLoRaWANVersion.UnmarshalBinary(data)
}
189396
func (p *Preference) UnmarshalBinary(b []byte) error {
	if len(b) != 1 {
		return io.ErrUnexpectedEOF
	}

	*p = Preference(b[0])
	return nil
}
862475
func (p *LinkADRAnsPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is expected")
	}
	if data[0]&(1<<0) > 0 {
		p.ChannelMaskACK = true
	}
	if data[0]&(1<<1) > 0 {
		p.DataRateACK = true
	}
	if data[0]&(1<<2) > 0 {
		p.PowerACK = true
	}
	return nil
}
479269
func (meta *Meta) UnmarshalBinary(data []byte) error {
	return meta.ReadBinary(bytes.NewReader(data))
}
348591
func (s *StatusCode) UnmarshalBinary(p []byte) error {
	b := buffer.New(p)
	// Too short to contain valid StatusCode
	if b.Len() < 2 {
		return io.ErrUnexpectedEOF
	}

	s.Code = dhcp6.Status(b.Read16())
	s.Message = string(b.Remaining())
	return nil
}
522878
func (o *UUID) UnmarshalBinary(bytes []byte) error {
	if len(bytes) != o.Size() {
		return errors.New("uuid: invalid length")
	}
	o.unmarshal(bytes)
	return nil
}
668152
func (u *Uint32) UnmarshalBinary(p []byte) error {
	b := uio.NewBigEndianBuffer(p)
	*u = Uint32(b.Read32())
	return b.FinError()
}
1235638
func (n *NetID) UnmarshalBinary(data []byte) error {
	if len(data) != len(n) {
		return fmt.Errorf("lorawan: %d bytes of data are expected", len(n))
	}

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

	return nil
}
1254725
func (p *AppTimeReqPayload) UnmarshalBinary(data []byte) error {
	if len(data) < p.Size() {
		return fmt.Errorf("lorawan/applayer/clocksync: %d bytes are expected", p.Size())
	}

	p.DeviceTime = binary.LittleEndian.Uint32(data[0:4])
	p.Param.TokenReq = uint8(data[4] & 0x0f)
	if data[4]&(1<<4) != 0 {
		p.Param.AnsRequired = true
	}

	return nil
}
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
}
864430
func (n *NetID) UnmarshalBinary(data []byte) error {
	if len(data) != 3 {
		return errors.New("ttn/core: Invalid length for NetID")
	}
	copy(n[:], data)
	return nil
}