blob: 90761a2d70a0426874a9956b7da15f5b55947861 [file] [log] [blame]
Harald Welte92c45f32010-06-12 18:59:38 +02001/*-
2 * Copyright (c) 2003, 2005, 2006 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
5 */
6#include <asn_internal.h>
7#include <ENUMERATED.h>
8#include <NativeEnumerated.h>
9#include <asn_codecs_prim.h> /* Encoder and decoder of a primitive type */
10
11/*
12 * ENUMERATED basic type description.
13 */
14static ber_tlv_tag_t asn_DEF_ENUMERATED_tags[] = {
15 (ASN_TAG_CLASS_UNIVERSAL | (10 << 2))
16};
17asn_TYPE_descriptor_t asn_DEF_ENUMERATED = {
18 "ENUMERATED",
19 "ENUMERATED",
20 ASN__PRIMITIVE_TYPE_free,
21 INTEGER_print, /* Implemented in terms of INTEGER */
22 asn_generic_no_constraint,
23 ber_decode_primitive,
24 INTEGER_encode_der, /* Implemented in terms of INTEGER */
25 INTEGER_decode_xer, /* This is temporary! */
26 INTEGER_encode_xer,
27 ENUMERATED_decode_uper, /* Unaligned PER decoder */
28 ENUMERATED_encode_uper, /* Unaligned PER encoder */
29 0, /* Use generic outmost tag fetcher */
30 asn_DEF_ENUMERATED_tags,
31 sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]),
32 asn_DEF_ENUMERATED_tags, /* Same as above */
33 sizeof(asn_DEF_ENUMERATED_tags) / sizeof(asn_DEF_ENUMERATED_tags[0]),
34 0, /* No PER visible constraints */
35 0, 0, /* No members */
36 0 /* No specifics */
37};
38
39asn_dec_rval_t
40ENUMERATED_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
41 asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
42 asn_dec_rval_t rval;
43 ENUMERATED_t *st = (ENUMERATED_t *)*sptr;
44 long value;
45 void *vptr = &value;
46
47 if(!st) {
48 st = (ENUMERATED_t *)(*sptr = CALLOC(1, sizeof(*st)));
49 if(!st) _ASN_DECODE_FAILED;
50 }
51
52 rval = NativeEnumerated_decode_uper(opt_codec_ctx, td, constraints,
53 (void **)&vptr, pd);
54 if(rval.code == RC_OK)
55 if(asn_long2INTEGER(st, value))
56 rval.code = RC_FAIL;
57 return rval;
58}
59
60asn_enc_rval_t
61ENUMERATED_encode_uper(asn_TYPE_descriptor_t *td,
62 asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
63 ENUMERATED_t *st = (ENUMERATED_t *)sptr;
64 long value;
65
66 if(asn_INTEGER2long(st, &value))
67 _ASN_ENCODE_FAILED;
68
69 return NativeEnumerated_encode_uper(td, constraints, &value, po);
70}
71