func (f *PacketRateFields) UnmarshalBinary(b []byte) error {
	l := len(b)
	if l < 2 {
		return io.ErrUnexpectedEOF
	}
	f.Flags = b[0]
	offset := 1
	if has1stBit(f.Flags) {
		if l < offset+3 {
			return io.ErrUnexpectedEOF
		}
		f.UplinkTimeUnit = b[offset]
		f.UplinkPacketRate = binary.BigEndian.Uint16(b[offset+1 : offset+3])
		offset += 3
	}
	if has2ndBit(f.Flags) {
		if l < offset+3 {
			return io.ErrUnexpectedEOF
		}
		f.DownlinkTimeUnit = b[offset]
		f.DownlinkPacketRate = binary.BigEndian.Uint16(b[offset+1 : offset+3])
	}
	return nil
}
UnmarshalBinary parses b into IE.
package ie
import (
	"encoding/binary"
	"io"
)
const (
	TimeUnitMinute   uint8 = 0
	TimeUnit6Minutes uint8 = 1
	TimeUnitHour     uint8 = 2
	TimeUnitDay      uint8 = 3
	TimeUnitWeek     uint8 = 4
)
func NewPacketRate(flags uint8, ulunit uint8, ulpackets uint16, dlunit uint8, dlpackets uint16) *IE {
	fields := NewPacketRateFields(flags, ulunit, ulpackets, dlunit, dlpackets)
	b, err := fields.Marshal()
	if err != nil {
		return nil
	}
	return New(PacketRate, b)
}
func (i *IE) PacketRate() (*PacketRateFields, error) {
	switch i.Type {
	case PacketRate:
		f, err := ParsePacketRateFields(i.Payload)
		if err != nil {
			return nil, err
		}
		return f, nil
	case CreateQER:
		ies, err := i.CreateQER()
		if err != nil {
			return nil, err
		}
		for _, x := range ies {
			if x.Type == PacketRate {
				return x.PacketRate()
			}
		}
		return nil, ErrIENotFound
	case UpdateQER:
		ies, err := i.UpdateQER()
		if err != nil {
			return nil, err
		}
		for _, x := range ies {
			if x.Type == PacketRate {
				return x.PacketRate()
			}
		}
		return nil, ErrIENotFound
	default:
		return nil, &InvalidTypeError{Type: i.Type}
	}
}
func (i *IE) HasDLPR() bool {
	if i.Type != PacketRate {
		return false
	}
	if len(i.Payload) < 1 {
		return false
	}
	return has2ndBit(i.Payload[0])
}
func (i *IE) HasULPR() bool {
	if i.Type != PacketRate {
		return false
	}
	if len(i.Payload) < 1 {
		return false
	}
	return has1stBit(i.Payload[0])
}
type PacketRateFields struct {
	Flags              uint8
	UplinkTimeUnit     uint8
	DownlinkTimeUnit   uint8
	UplinkPacketRate   uint16
	DownlinkPacketRate uint16
}
func NewPacketRateFields(flags uint8, ulunit uint8, ulpackets uint16, dlunit uint8, dlpackets uint16) *PacketRateFields {
	f := &PacketRateFields{Flags: flags}
	if has1stBit(flags) {
		f.UplinkTimeUnit = ulunit
		f.UplinkPacketRate = ulpackets
	}
	if has2ndBit(flags) {
		f.DownlinkTimeUnit = dlunit
		f.DownlinkPacketRate = dlpackets
	}
	return f
}
func ParsePacketRateFields(b []byte) (*PacketRateFields, error) {
	f := &PacketRateFields{}
	if err := f.UnmarshalBinary(b); err != nil {
		return nil, err
	}
	return f, nil
}