/*
 * Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
 * From ASN.1 module "X2AP-IEs"
 * 	found in "Spec/e2ap-v031ex.asn"
 * 	`asn1c -fcompound-names -fno-include-deps -findirect-choice -gen-PER`
 */

#include "MeasurementsToActivate.h"

int
MeasurementsToActivate_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
			asn_app_constraint_failed_f *ctfailcb, void *app_key) {
	const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
	size_t size;
	
	if(!sptr) {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: value not given (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	if(st->size > 0) {
		/* Size in bits */
		size = 8 * st->size - (st->bits_unused & 0x07);
	} else {
		size = 0;
	}
	
	if((size == 8)) {
		/* 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 BIT_STRING,
 * so here we adjust the DEF accordingly.
 */
static asn_oer_constraints_t asn_OER_type_MeasurementsToActivate_constr_1 CC_NOTUSED = {
	{ 0, 0 },
	8	/* (SIZE(8..8)) */};
asn_per_constraints_t asn_PER_type_MeasurementsToActivate_constr_1 CC_NOTUSED = {
	{ APC_UNCONSTRAINED,	-1, -1,  0,  0 },
	{ APC_CONSTRAINED,	 0,  0,  8,  8 }	/* (SIZE(8..8)) */,
	0, 0	/* No PER value map */
};
static const ber_tlv_tag_t asn_DEF_MeasurementsToActivate_tags_1[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (3 << 2))
};
asn_TYPE_descriptor_t asn_DEF_MeasurementsToActivate = {
	"MeasurementsToActivate",
	"MeasurementsToActivate",
	&asn_OP_BIT_STRING,
	asn_DEF_MeasurementsToActivate_tags_1,
	sizeof(asn_DEF_MeasurementsToActivate_tags_1)
		/sizeof(asn_DEF_MeasurementsToActivate_tags_1[0]), /* 1 */
	asn_DEF_MeasurementsToActivate_tags_1,	/* Same as above */
	sizeof(asn_DEF_MeasurementsToActivate_tags_1)
		/sizeof(asn_DEF_MeasurementsToActivate_tags_1[0]), /* 1 */
	{ &asn_OER_type_MeasurementsToActivate_constr_1, &asn_PER_type_MeasurementsToActivate_constr_1, MeasurementsToActivate_constraint },
	0, 0,	/* No members */
	&asn_SPC_BIT_STRING_specs	/* Additional specs */
};

