// UnmarshalRolePB decodes a role from binary protobuf data.
972114
func UnmarshalRolePB(data []byte, r *Role) error {
	return proto.Unmarshal(data, r)
}
328008
func (p *RejoinParamSetupReqPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is exepcted")
	}

	p.MaxCountN = data[0] & ((1 << 3) | (1 << 2) | (1 << 1) | 1)
	p.MaxTimeN = (data[0] & ((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4))) >> 4

	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
}
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
}
1061608
func (r *Packet) UnmarshalBinary(data []byte) error {
	err := r.Header.UnmarshalBinary(data)
	if err != nil {
		return err
	}

	r.Payload = data[r.HeaderSize:r.PacketSize]

	return nil
}
1045955
func (u *Unmarshaler) Unmarshal(r io.Reader, pb proto.Message) error {
	dec := json.NewDecoder(r)
	return u.UnmarshalNext(dec, pb)
}
759453
func (u *Unmarshaler) UnmarshalNext(dec *json.Decoder, pb proto.Message) error {
	inputValue := json.RawMessage{}
	if err := dec.Decode(&inputValue); err != nil {
		return err
	}
	if err := u.unmarshalValue(reflect.ValueOf(pb).Elem(), inputValue, nil); err != nil {
		return err
	}
	return checkRequiredFields(pb)
}
799011
func UnmarshalUserPB(data []byte, u *User) error {
	return proto.Unmarshal(data, u)
}
890576
func (c *Command) UnmarshalBinary(uplink bool, data []byte) error {
	if len(data) == 0 {
		return errors.New("lorawan/applayer/multicastsetup: at least 1 byte is expected")
	}

	c.CID = CID(data[0])

	p, err := GetCommandPayload(uplink, c.CID)
	if err != nil {
		if err == ErrNoPayloadForCID {
			return nil
		}
		return err
	}

	c.Payload = p
	if err := c.Payload.UnmarshalBinary(data[1:]); err != nil {
		return err
	}

	return nil
}
199568
func (addr *DevAddr) UnmarshalBinary(data []byte) error {
	if len(data) != 4 {
		return errors.New("ttn/core: Invalid length for DevAddr")
	}
	copy(addr[:], data)
	return nil
}
824194
func (p *RejoinParamSetupAnsPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is expected")
	}

	p.TimeOK = data[0]&1 != 0
	return nil
}
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
}
170283
func (s *SubnetMask) UnmarshalBinary(p []byte) error {
	buf := uio.NewBigEndianBuffer(p)
	*s = buf.CopyN(net.IPv4len)
	return buf.FinError()
}
424841
func (p *BeaconFreqAnsPayload) UnmarshalBinary(data []byte) error {
	if len(data) != 1 {
		return errors.New("lorawan: 1 byte of data is expected")
	}

	p.BeaconFrequencyOK = data[0]&(1<<0) != 0

	return nil
}
649708
func UnmarshalBinary(data []byte, fields ...interface{}) error {
	buf := bytes.NewBuffer(data)

	for _, p := range fields {
		switch m := p.(type) {
		case encoding.BinaryUnmarshaler:
			return m.UnmarshalBinary(buf.Bytes())
		case *[]byte:
			*m = buf.Bytes()
			return nil
		default:
			err := binary.Read(buf, binary.LittleEndian, p)
			if err != nil {
				return ProtocolError(err)
			}
		}
	}

	return nil
}
683904
func (p *CFListChannelPayload) UnmarshalBinary(uplink bool, data []byte) error {
	if len(data) > 15 {
		return errors.New("lorawan: max length is 15 bytes")
	}

	if len(data)%3 != 0 {
		return errors.New("lorawan: length must be a multiple of 3")
	}

	for i := 0; i < len(data)/3; i++ {
		p.Channels[i] = binary.LittleEndian.Uint32([]byte{
			data[i*3],
			data[i*3+1],
			data[i*3+2],
			0,
		}) * 100
	}

	return nil
}
504046
func UnmarshalRole(data []byte, opts ...MarshalOption) (*RoleV3, error) {
	var h ResourceHeader
	err := json.Unmarshal(data, &h)
	if err != nil {
		h.Version = V2
	}

	cfg, err := collectOptions(opts)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	switch h.Version {
	case V2:
		var role RoleV2
		if err := utils.UnmarshalWithSchema(GetRoleSchema(V2, ""), &role, data); err != nil {
			return nil, trace.BadParameter(err.Error())
		}

		if err := role.CheckAndSetDefaults(); err != nil {
			return nil, trace.Wrap(err)
		}

		roleV3 := role.V3()
		roleV3.SetResourceID(cfg.ID)
		return roleV3, nil
	case V3:
		var role RoleV3
		if cfg.SkipValidation {
			if err := utils.FastUnmarshal(data, &role); err != nil {
				return nil, trace.BadParameter(err.Error())
			}
		} else {
			if err := utils.UnmarshalWithSchema(GetRoleSchema(V3, ""), &role, data); err != nil {
				return nil, trace.BadParameter(err.Error())
			}
		}

		if err := role.CheckAndSetDefaults(); err != nil {
			return nil, trace.Wrap(err)
		}

		if cfg.ID != 0 {
			role.SetResourceID(cfg.ID)
		}
		if !cfg.Expires.IsZero() {
			role.SetExpiry(cfg.Expires)
		}
		return &role, nil
	}

	return nil, trace.BadParameter("role version %q is not supported", h.Version)
}