// UnmarshalBinary decodes b from a binary-encoded byte slice. data can be in
// either official roaring format or Pilosa's roaring format.
769907
func (b *Bitmap) UnmarshalBinary(data []byte) error {
	if data == nil {
		// Nothing to unmarshal
		return nil
	}
	statsHit("Bitmap/UnmarshalBinary")
	b.opN = 0 // reset opN since we're reading new data.
	fileMagic := uint32(binary.LittleEndian.Uint16(data[0:2]))
	if fileMagic == MagicNumber { // if pilosa roaring
		return errors.Wrap(b.unmarshalPilosaRoaring(data), "unmarshaling as pilosa roaring")
	}

	keyN, containerTyper, header, pos, haveRuns, err := readOfficialHeader(data)
	if err != nil {
		return errors.Wrap(err, "reading roaring header")
	}

	b.Containers.Reset()
	// Descriptive header section: Read container keys and cardinalities.
	for i, buf := uint(0), data[header:]; i < uint(keyN); i, buf = i+1, buf[4:] {
		card := int(binary.LittleEndian.Uint16(buf[2:4])) + 1
		b.Containers.PutContainerValues(
			uint64(binary.LittleEndian.Uint16(buf[0:2])),
			containerTyper(i, card), /// container type voodo with isRunBitmap
			card,
			true)
	}

	// Read container offsets and attach data.
	if haveRuns {
		readWithRuns(b, data, pos, keyN)
	} else {
		err := readOffsets(b, data, pos, keyN)
		if err != nil {
			return errors.Wrap(err, "reading offsets from official roaring format")
		}
	}
	return nil
}
479269
func (meta *Meta) UnmarshalBinary(data []byte) error {
	return meta.ReadBinary(bytes.NewReader(data))
}
304116
func (p *RekeyIndPayload) UnmarshalBinary(data []byte) error {
	return p.DevLoRaWANVersion.UnmarshalBinary(data)
}
1001206
func (h *TLFReaderKeyBundleID) UnmarshalBinary(data []byte) error {
	return h.h.UnmarshalBinary(data)
}
325760
func (u *URL) UnmarshalBinary(b []byte) error {
	uu, err := url.Parse(string(b))
	if err != nil {
		return err
	}

	*u = URL(*uu)
	return nil
}
260689
func (e *EUI64) UnmarshalBinary(data []byte) error {
	if len(data) != len(e) {
		return fmt.Errorf("lorawan: %d bytes of data are expected", len(e))
	}
	for i, v := range data {
		// little endian
		e[len(e)-i-1] = v
	}
	return nil
}
1210789
func (m *ChMask) UnmarshalBinary(data []byte) error {
	if len(data) != 2 {
		return errors.New("lorawan: 2 bytes of data are expected")
	}
	for i, b := range data {
		for j := uint8(0); j < 8; j++ {
			if b&(1<<j) > 0 {
				m[uint8(i)*8+j] = true
			}
		}
	}
	return nil
}
707542
func (a *App) UnmarshalBinary(b []byte) error {
	return json.Unmarshal(b, a)
}
424340
func (p *ADRParamSetupReqPayload) UnmarshalBinary(data []byte) error {
	return p.ADRParam.UnmarshalBinary(data)
}
806264
func (p *FragSessionSetupReqPayload) UnmarshalBinary(data []byte) error {
	if len(data) < p.Size() {
		return fmt.Errorf("lorawan/applayer/fragmentation: %d bytes are expected", p.Size())
	}

	// Fragmentation
	for i := range p.FragSession.McGroupBitMask {
		p.FragSession.McGroupBitMask[i] = data[0]&(1<<uint8(i)) != 0
	}
	p.FragSession.FragIndex = (data[0] >> 4) & 0x03

	// NbFrag
	p.NbFrag = binary.LittleEndian.Uint16(data[1:3])

	// FragSize
	p.FragSize = data[3]

	// Control
	p.Control.BlockAckDelay = data[4] & 0x07
	p.Control.FragmentationMatrix = (data[4] >> 3) & 0x07

	// Padding
	p.Padding = data[5]

	// Descriptor
	copy(p.Descriptor[:], data[6:10])

	return nil
}
728836
func (bf *BitField) UnmarshalBinary(bs []byte) error {
	buf := bytes.NewBuffer(bs)
	n, err := binary.ReadUvarint(buf)
	if err != nil {
		return err
	}
	if n > math.MaxUint32 {
		return fmt.Errorf("encoded number is out of range: %d > %d", n, uint32(math.MaxUint32))
	}

	size := uint32(n)
	if size == 0 {
		bf.size = 0
		bf.data = nil
		return nil
	}
	data := buf.Bytes()
	if uint32(len(data)) != (size+8-1)>>3 {
		return fmt.Errorf("mismatched size (%d) v. byte count (%d)", size, len(data))
	}

	bf.size = size
	bf.data = data
	return nil
}
172963
func (f *FileNameV3) UnmarshalBinary(data []byte) error {
	buf := bytes.NewBuffer(data)

	fields := []interface{}{
		&f.Length, &f.Flags, &f.CaseType, &f.ID,
	}

	for _, p := range fields {
		if err := binary.Read(buf, binary.LittleEndian, p); err != nil {
			return err
		}
	}

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

	return nil
}
621288
func (p *Property) UnmarshalBinary(data []byte) error {
	buf := bytes.NewBuffer(data)

	err := binary.Read(buf, binary.LittleEndian, &p.header)
	if err != nil {
		return err
	}

	switch p.header.Kind {
	case vixPropertyTypeBool:
		return binary.Read(buf, binary.LittleEndian, &p.data.Bool)
	case vixPropertyTypeInt32:
		return binary.Read(buf, binary.LittleEndian, &p.data.Int32)
	case vixPropertyTypeInt64:
		return binary.Read(buf, binary.LittleEndian, &p.data.Int64)
	case vixPropertyTypeString:
		s := make([]byte, p.header.Length)
		if _, err := buf.Read(s); err != nil {
			return err
		}

		p.data.String = string(bytes.TrimRight(s, "\x00"))
	case vixPropertyTypeBlob:
		p.data.Blob = make([]byte, p.header.Length)
		if _, err := buf.Read(p.data.Blob); err != nil {
			return err
		}
	default:
		return errors.New("VIX_E_UNRECOGNIZED_PROPERTY")
	}

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

	p.PackageIdentifier = data[0]
	p.PackageVersion = data[1]
	return nil
}
46972
func (t *UnixTime) UnmarshalBinary(raw []byte) error {
	var nanosecondsSinceEpoch int64

	if err := binary.Read(bytes.NewReader(raw), binary.LittleEndian, &nanosecondsSinceEpoch); err != nil {
		return err
	}
	*t = NewUnixTimeFromNanoseconds(nanosecondsSinceEpoch)
	return nil
}
1357129
func (r *CommandHgfsSendPacket) UnmarshalBinary(data []byte) error {
	buf := bytes.NewBuffer(data)

	err := binary.Read(buf, binary.LittleEndian, &r.Body)
	if err != nil {
		return err
	}

	r.Packet = buf.Next(int(r.Body.PacketSize))

	return nil
}
1319220
func (id *ULID) UnmarshalBinary(data []byte) error {
	if len(data) != len(*id) {
		return ErrDataSize
	}

	copy((*id)[:], data)
	return nil
}