func (v VendorID) MarshalText() ([]byte, error) {
	return Buffer(v[:]).MarshalText()
}
MarshalText implements encoding.TextMarshaler.
package interop
import (
	"encoding/hex"
	"encoding/json"
	"strings"
	"go.thethings.network/lorawan-stack/v3/pkg/errors"
	"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
	"go.thethings.network/lorawan-stack/v3/pkg/types"
)
type ProtocolVersion string
const (
	ProtocolV1_0 = "1.0"
	ProtocolV1_1 = "1.1"
)
var errUnknownProtocol = errors.DefineInvalidArgument("unknown_protocol", "unknown protocol")
func (p *ProtocolVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {
	var s string
	if err := unmarshal(&s); err != nil {
		return err
	}
	switch s {
	case "BI1.0":
		*p = ProtocolV1_0
		return nil
	case "BI1.1":
		*p = ProtocolV1_1
		return nil
	default:
		return errUnknownProtocol.New()
	}
}
func (p ProtocolVersion) SupportsNSID() bool {
	switch p {
	case ProtocolV1_1:
		return true
	default:
		return false
	}
}
type MessageType string
const (
	MessageTypeJoinReq     MessageType = "JoinReq"
	MessageTypeJoinAns     MessageType = "JoinAns"
	MessageTypeRejoinReq   MessageType = "RejoinReq"
	MessageTypeRejoinAns   MessageType = "RejoinAns"
	MessageTypeAppSKeyReq  MessageType = "AppSKeyReq"
	MessageTypeAppSKeyAns  MessageType = "AppSKeyAns"
	MessageTypePRStartReq  MessageType = "PRStartReq"
	MessageTypePRStartAns  MessageType = "PRStartAns"
	MessageTypePRStopReq   MessageType = "PRStopReq"
	MessageTypePRStopAns   MessageType = "PRStopAns"
	MessageTypeHRStartReq  MessageType = "HRStartReq"
	MessageTypeHRStartAns  MessageType = "HRStartAns"
	MessageTypeHRStopReq   MessageType = "HRStopReq"
	MessageTypeHRStopAns   MessageType = "HRStopAns"
	MessageTypeHomeNSReq   MessageType = "HomeNSReq"
	MessageTypeHomeNSAns   MessageType = "HomeNSAns"
	MessageTypeProfileReq  MessageType = "ProfileReq"
	MessageTypeProfileAns  MessageType = "ProfileAns"
	MessageTypeXmitDataReq MessageType = "XmitDataReq"
	MessageTypeXmitDataAns MessageType = "XmitDataAns"
)
var requestAnswers = map[MessageType]MessageType{
	MessageTypeJoinReq:     MessageTypeJoinAns,
	MessageTypeRejoinReq:   MessageTypeRejoinAns,
	MessageTypeAppSKeyReq:  MessageTypeAppSKeyAns,
	MessageTypePRStartReq:  MessageTypePRStartAns,
	MessageTypePRStopReq:   MessageTypePRStopAns,
	MessageTypeHRStartReq:  MessageTypeHRStartAns,
	MessageTypeHRStopReq:   MessageTypeHRStopAns,
	MessageTypeHomeNSReq:   MessageTypeHomeNSAns,
	MessageTypeProfileReq:  MessageTypeProfileAns,
	MessageTypeXmitDataReq: MessageTypeXmitDataAns,
}
var protocolMessageTypes = map[ProtocolVersion]map[MessageType]bool{
	ProtocolV1_0: {
		MessageTypeJoinReq:     true,
		MessageTypeJoinAns:     true,
		MessageTypeAppSKeyReq:  true,
		MessageTypeAppSKeyAns:  true,
		MessageTypePRStartReq:  true,
		MessageTypePRStartAns:  true,
		MessageTypePRStopReq:   true,
		MessageTypePRStopAns:   true,
		MessageTypeHRStartReq:  true,
		MessageTypeHRStartAns:  true,
		MessageTypeHRStopReq:   true,
		MessageTypeHRStopAns:   true,
		MessageTypeHomeNSReq:   true,
		MessageTypeHomeNSAns:   true,
		MessageTypeProfileReq:  true,
		MessageTypeProfileAns:  true,
		MessageTypeXmitDataReq: true,
		MessageTypeXmitDataAns: true,
	},
	ProtocolV1_1: {
		MessageTypeJoinReq:     true,
		MessageTypeJoinAns:     true,
		MessageTypeRejoinReq:   true,
		MessageTypeRejoinAns:   true,
		MessageTypeAppSKeyReq:  true,
		MessageTypeAppSKeyAns:  true,
		MessageTypePRStartReq:  true,
		MessageTypePRStartAns:  true,
		MessageTypePRStopReq:   true,
		MessageTypePRStopAns:   true,
		MessageTypeHRStartReq:  true,
		MessageTypeHRStartAns:  true,
		MessageTypeHRStopReq:   true,
		MessageTypeHRStopAns:   true,
		MessageTypeHomeNSReq:   true,
		MessageTypeHomeNSAns:   true,
		MessageTypeProfileReq:  true,
		MessageTypeProfileAns:  true,
		MessageTypeXmitDataReq: true,
		MessageTypeXmitDataAns: true,
	},
}
func (m MessageType) IsRequest() bool {
	_, ok := requestAnswers[m]
	return ok
}
func (m MessageType) Answer() (MessageType, bool) {
	ans, ok := requestAnswers[m]
	return ans, ok
}
func (m MessageType) Validate(version ProtocolVersion) error {
	protocolMessageTypes, ok := protocolMessageTypes[version]
	if !ok {
		return ErrProtocolVersion.New()
	}
	for mt := range protocolMessageTypes {
		if mt == m {
			return nil
		}
	}
	return ErrMalformedMessage.New()
}
func (m MessageType) ToJoinServer() bool {
	switch m {
	case MessageTypeJoinReq,
		MessageTypeRejoinReq,
		MessageTypeAppSKeyReq,
		MessageTypeHomeNSReq:
		return true
	default:
		return false
	}
}
type ResultCode string
const (
	ResultSuccess              ResultCode = "Success"
	ResultNoAction             ResultCode = "NoAction"
	ResultMICFailed            ResultCode = "MICFailed"
	ResultFrameReplayed        ResultCode = "FrameReplayed"
	ResultJoinReqFailed        ResultCode = "JoinReqFailed"
	ResultNoRoamingAgreement   ResultCode = "NoRoamingAgreement"
	ResultDevRoamingDisallowed ResultCode = "DevRoamingDisallowed"
	ResultRoamingActDisallowed ResultCode = "RoamingActDisallowed"
	ResultActivationDisallowed ResultCode = "ActivationDisallowed"
	ResultUnknownDevEUI        ResultCode = "UnknownDevEUI"
	ResultUnknownDevAddr       ResultCode = "UnknownDevAddr"
	ResultUnknownSender        ResultCode = "UnknownSender"
	ResultUnkownReceiver       ResultCode = "UnkownReceiver"  
	ResultUnknownReceiver        ResultCode = "UnknownReceiver"
	ResultDeferred               ResultCode = "Deferred"
	ResultXmitFailed             ResultCode = "XmitFailed"
	ResultInvalidFPort           ResultCode = "InvalidFPort"
	ResultInvalidProtocolVersion ResultCode = "InvalidProtocolVersion"
	ResultStaleDeviceProfile     ResultCode = "StaleDeviceProfile"
	ResultMalformedRequest       ResultCode = "MalformedRequest"
	ResultMalformedMessage       ResultCode = "MalformedMessage"
	ResultFrameSizeError         ResultCode = "FrameSizeError"
	ResultOther                  ResultCode = "Other"
)
type MACVersion ttnpb.MACVersion
func (v MACVersion) MarshalText() ([]byte, error) {
	var res string
	switch ttnpb.MACVersion(v) {
	case ttnpb.MAC_V1_0:
		res = "1.0"
	case ttnpb.MAC_V1_0_1:
		res = "1.0.1"
	case ttnpb.MAC_V1_0_2:
		res = "1.0.2"
	case ttnpb.MAC_V1_0_3:
		res = "1.0.3"
	case ttnpb.MAC_V1_0_4:
		res = "1.0.4"
	case ttnpb.MAC_V1_1:
		res = "1.1"
	default:
		return nil, errUnknownMACVersion.New()
	}
	return []byte(res), nil
}
func (v *MACVersion) UnmarshalText(data []byte) error {
	var res ttnpb.MACVersion
	switch string(data) {
	case "1.0":
		res = ttnpb.MAC_V1_0
	case "1.0.1":
		res = ttnpb.MAC_V1_0_1
	case "1.0.2":
		res = ttnpb.MAC_V1_0_2
	case "1.0.3":
		res = ttnpb.MAC_V1_0_3
	case "1.0.4":
		res = ttnpb.MAC_V1_0_4
	case "1.1":
		res = ttnpb.MAC_V1_1
	default:
		return errUnknownMACVersion.New()
	}
	*v = MACVersion(res)
	return nil
}
type Buffer []byte
func (b Buffer) MarshalText() ([]byte, error) {
	return []byte(strings.ToUpper(hex.EncodeToString(b))), nil
}
func (b *Buffer) UnmarshalText(data []byte) error {
	buf, err := hex.DecodeString(strings.TrimPrefix(string(data), "0x"))
	if err != nil {
		return err
	}
	*b = Buffer(buf)
	return nil
}
type VendorID [3]byte