/*
 * Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
 * From ASN.1 module "E2SM-RC-IEs"
 * 	found in "e2sm-rc-nov2021.asn"
 * 	`asn1c -fcompound-names -fno-include-deps -findirect-choice -pdu=auto -gen-PER -gen-OER -no-gen-example -D .`
 */

#include "IndexToRFSP.h"

int
IndexToRFSP_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
			asn_app_constraint_failed_f *ctfailcb, void *app_key) {
	long value;
	
	if(!sptr) {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: value not given (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	value = *(const long *)sptr;
	
	if((value >= 1 && value <= 256)) {
		/* Constraint check succeeded */
		return 0;
	} else {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: constraint failed (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
}

/*
 * This type is implemented using NativeInteger,
 * so here we adjust the DEF accordingly.
 */
static asn_oer_constraints_t asn_OER_type_IndexToRFSP_constr_1 CC_NOTUSED = {
	{ 0, 0 },
	-1};
static asn_per_constraints_t asn_PER_type_IndexToRFSP_constr_1 CC_NOTUSED = {
	{ APC_CONSTRAINED | APC_EXTENSIBLE,  8,  8,  1,  256 }	/* (1..256,...) */,
	{ APC_UNCONSTRAINED,	-1, -1,  0,  0 },
	0, 0	/* No PER value map */
};
static const ber_tlv_tag_t asn_DEF_IndexToRFSP_tags_1[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
};
asn_TYPE_descriptor_t asn_DEF_IndexToRFSP = {
	"IndexToRFSP",
	"IndexToRFSP",
	&asn_OP_NativeInteger,
	asn_DEF_IndexToRFSP_tags_1,
	sizeof(asn_DEF_IndexToRFSP_tags_1)
		/sizeof(asn_DEF_IndexToRFSP_tags_1[0]), /* 1 */
	asn_DEF_IndexToRFSP_tags_1,	/* Same as above */
	sizeof(asn_DEF_IndexToRFSP_tags_1)
		/sizeof(asn_DEF_IndexToRFSP_tags_1[0]), /* 1 */
	{ &asn_OER_type_IndexToRFSP_constr_1, &asn_PER_type_IndexToRFSP_constr_1, IndexToRFSP_constraint },
	0, 0,	/* No members */
	0	/* No specifics */
};

