func (v *KeySecurity) UnmarshalJSON(b []byte) error {
	if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
		return v.UnmarshalText(b[1 : len(b)-1])
	}
	i, err := strconv.Atoi(string(b))
	if err != nil {
		return errCouldNotParse("KeySecurity")(string(b)).WithCause(err)
	}
	*v = KeySecurity(i)
	return nil
}
UnmarshalJSON implements json.Unmarshaler interface.
package ttnpb
import (
	"strconv"
	"strings"
	"github.com/gogo/protobuf/jsonpb"
)
func (v DownlinkPathConstraint) MarshalText() ([]byte, error) {
	return []byte(v.String()), nil
}
func (v *DownlinkPathConstraint) UnmarshalText(b []byte) error {
	s := string(b)
	if i, ok := DownlinkPathConstraint_value[s]; ok {
		*v = DownlinkPathConstraint(i)
		return nil
	}
	if !strings.HasPrefix(s, "DOWNLINK_PATH_CONSTRAINT_") {
		if i, ok := DownlinkPathConstraint_value["DOWNLINK_PATH_CONSTRAINT_"+s]; ok {
			*v = DownlinkPathConstraint(i)
			return nil
		}
	}
	return errCouldNotParse("DownlinkPathConstraint")(string(b))
}
func (v *DownlinkPathConstraint) UnmarshalJSON(b []byte) error {
	if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
		return v.UnmarshalText(b[1 : len(b)-1])
	}
	i, err := strconv.Atoi(string(b))
	if err != nil {
		return errCouldNotParse("DownlinkPathConstraint")(string(b)).WithCause(err)
	}
	*v = DownlinkPathConstraint(i)
	return nil
}
func (v State) MarshalText() ([]byte, error) {
	return []byte(v.String()), nil
}
func (v *State) UnmarshalText(b []byte) error {
	s := string(b)
	if i, ok := State_value[s]; ok {
		*v = State(i)
		return nil
	}
	if !strings.HasPrefix(s, "STATE_") {
		if i, ok := State_value["STATE_"+s]; ok {
			*v = State(i)
			return nil
		}
	}
	return errCouldNotParse("State")(string(b))
}
func (v *State) UnmarshalJSON(b []byte) error {
	if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
		return v.UnmarshalText(b[1 : len(b)-1])
	}
	i, err := strconv.Atoi(string(b))
	if err != nil {
		return errCouldNotParse("State")(string(b)).WithCause(err)
	}
	*v = State(i)
	return nil
}
func (v KeyProvisioning) MarshalText() ([]byte, error) {
	switch v {
	case KeyProvisioning_KEY_PROVISIONING_UNKNOWN:
		return []byte("unknown"), nil
	case KeyProvisioning_KEY_PROVISIONING_CUSTOM:
		return []byte("custom"), nil
	case KeyProvisioning_KEY_PROVISIONING_JOIN_SERVER:
		return []byte("join server"), nil
	case KeyProvisioning_KEY_PROVISIONING_MANIFEST:
		return []byte("manifest"), nil
	}
	return []byte(v.String()), nil
}
func (v *KeyProvisioning) UnmarshalText(b []byte) error {
	s := string(b)
	if i, ok := KeyProvisioning_value[s]; ok {
		*v = KeyProvisioning(i)
		return nil
	}
	switch s {
	case "unknown", "KEY_PROVISIONING_UNKNOWN":
		*v = KeyProvisioning_KEY_PROVISIONING_UNKNOWN
	case "custom", "KEY_PROVISIONING_CUSTOM":
		*v = KeyProvisioning_KEY_PROVISIONING_CUSTOM
	case "join server", "KEY_PROVISIONING_JOIN_SERVER":
		*v = KeyProvisioning_KEY_PROVISIONING_JOIN_SERVER
	case "manifest", "KEY_PROVISIONING_MANIFEST":
		*v = KeyProvisioning_KEY_PROVISIONING_MANIFEST
	default:
		errCouldNotParse("KeyProvisioning")(string(b))
	}
	return nil
}
func (v *KeyProvisioning) UnmarshalJSON(b []byte) error {
	if len(b) > 2 && b[0] == '"' && b[len(b)-1] == '"' {
		return v.UnmarshalText(b[1 : len(b)-1])
	}
	i, err := strconv.Atoi(string(b))
	if err != nil {
		return errCouldNotParse("KeyProvisioning")(string(b)).WithCause(err)
	}
	*v = KeyProvisioning(i)
	return nil
}
func (v *KeyProvisioning) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, b []byte) error {
	return v.UnmarshalJSON(b)
}
func (v KeySecurity) MarshalText() ([]byte, error) {
	switch v {
	case KeySecurity_KEY_SECURITY_UNKNOWN:
		return []byte("unknown"), nil
	case KeySecurity_KEY_SECURITY_NONE:
		return []byte("none"), nil
	case KeySecurity_KEY_SECURITY_READ_PROTECTED:
		return []byte("read protected"), nil
	case KeySecurity_KEY_SECURITY_SECURE_ELEMENT:
		return []byte("secure element"), nil
	}
	return []byte(v.String()), nil
}
func (v *KeySecurity) UnmarshalText(b []byte) error {
	s := string(b)
	if i, ok := KeySecurity_value[s]; ok {
		*v = KeySecurity(i)
		return nil
	}
	switch s {
	case "unknown", "KEY_SECURITY_UNKNOWN":
		*v = KeySecurity_KEY_SECURITY_UNKNOWN
	case "none", "KEY_SECURITY_NONE":
		*v = KeySecurity_KEY_SECURITY_NONE
	case "read protected", "KEY_SECURITY_READ_PROTECTED":
		*v = KeySecurity_KEY_SECURITY_READ_PROTECTED
	case "secure element", "KEY_SECURITY_SECURE_ELEMENT":
		*v = KeySecurity_KEY_SECURITY_SECURE_ELEMENT
	default:
		errCouldNotParse("KeySecurity")(string(b))
	}
	return nil
}