2 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
8 #include <asn_application.h>
9 #include <asn_codecs_prim.h>
15 typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
17 extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
19 /* Map with <tag> to integer value association */
20 typedef struct asn_INTEGER_enum_map_s {
21 long nat_value; /* associated native integer value */
22 size_t enum_len; /* strlen("tag") */
23 const char *enum_name; /* "tag" */
24 } asn_INTEGER_enum_map_t;
26 /* This type describes an enumeration for INTEGER and ENUMERATED types */
27 typedef const struct asn_INTEGER_specifics_s {
28 const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
29 const unsigned int *enum2value; /* "tag" => N; sorted by tag */
30 int map_count; /* Elements in either map */
31 int extension; /* This map is extensible */
32 int strict_enumeration; /* Enumeration set is fixed */
33 int field_width; /* Size of native integer */
34 int field_unsigned; /* Signed=0, unsigned=1 */
35 } asn_INTEGER_specifics_t;
37 asn_struct_print_f INTEGER_print;
38 ber_type_decoder_f INTEGER_decode_ber;
39 der_type_encoder_f INTEGER_encode_der;
40 xer_type_decoder_f INTEGER_decode_xer;
41 xer_type_encoder_f INTEGER_encode_xer;
42 per_type_decoder_f INTEGER_decode_uper;
43 per_type_encoder_f INTEGER_encode_uper;
45 /***********************************
46 * Some handy conversion routines. *
47 ***********************************/
50 * Returns 0 if it was possible to convert, -1 otherwise.
51 * -1/EINVAL: Mandatory argument missing
52 * -1/ERANGE: Value encoded is out of range for long representation
53 * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()).
55 int asn_INTEGER2long(const INTEGER_t *i, long *l);
56 int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
57 int asn_long2INTEGER(INTEGER_t *i, long l);
58 int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
60 /* A a reified version of strtol(3) with nicer error reporting. */
61 enum asn_strtol_result_e {
62 ASN_STRTOL_ERROR_RANGE = -3, /* Input outside of numeric range for long type */
63 ASN_STRTOL_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */
64 ASN_STRTOL_EXPECT_MORE = -1, /* More data expected (e.g. "+") */
65 ASN_STRTOL_OK = 0, /* Conversion succeded, number ends at (*end) */
66 ASN_STRTOL_EXTRA_DATA = 1 /* Conversion succeded, but the string has extra stuff */
68 enum asn_strtol_result_e asn_strtol_lim(const char *str, const char **end, long *l);
70 /* The asn_strtol is going to be DEPRECATED soon */
71 enum asn_strtol_result_e asn_strtol(const char *str, const char *end, long *l);
74 * Convert the integer value into the corresponding enumeration map entry.
76 const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value);
82 #endif /* _INTEGER_H_ */