2 * Copyright (c) 2003-2017 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;
18 extern asn_TYPE_operation_t asn_OP_INTEGER;
20 /* Map with <tag> to integer value association */
21 typedef struct asn_INTEGER_enum_map_s {
22 long nat_value; /* associated native integer value */
23 size_t enum_len; /* strlen("tag") */
24 const char *enum_name; /* "tag" */
25 } asn_INTEGER_enum_map_t;
27 /* This type describes an enumeration for INTEGER and ENUMERATED types */
28 typedef struct asn_INTEGER_specifics_s {
29 const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
30 const unsigned int *enum2value; /* "tag" => N; sorted by tag */
31 int map_count; /* Elements in either map */
32 int extension; /* This map is extensible */
33 int strict_enumeration; /* Enumeration set is fixed */
34 int field_width; /* Size of native integer */
35 int field_unsigned; /* Signed=0, unsigned=1 */
36 } asn_INTEGER_specifics_t;
38 ssize_t INTEGER__dump(const asn_TYPE_descriptor_t *td,
40 asn_app_consume_bytes_f *cb,
41 void *app_key, int plainOrXER);
43 #define INTEGER_free ASN__PRIMITIVE_TYPE_free
45 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
46 asn_struct_print_f INTEGER_print;
47 #endif /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
49 asn_struct_compare_f INTEGER_compare;
51 #define INTEGER_constraint asn_generic_no_constraint
53 #if !defined(ASN_DISABLE_BER_SUPPORT)
54 #define INTEGER_decode_ber ber_decode_primitive
55 der_type_encoder_f INTEGER_encode_der;
56 #endif /* !defined(ASN_DISABLE_BER_SUPPORT) */
58 #if !defined(ASN_DISABLE_XER_SUPPORT)
59 xer_type_decoder_f INTEGER_decode_xer;
60 xer_type_encoder_f INTEGER_encode_xer;
61 #endif /* !defined(ASN_DISABLE_XER_SUPPORT) */
63 #if !defined(ASN_DISABLE_JER_SUPPORT)
64 jer_type_encoder_f INTEGER_encode_jer;
65 #endif /* !defined(ASN_DISABLE_JER_SUPPORT) */
67 #if !defined(ASN_DISABLE_OER_SUPPORT)
68 oer_type_decoder_f INTEGER_decode_oer;
69 oer_type_encoder_f INTEGER_encode_oer;
70 #endif /* !defined(ASN_DISABLE_OER_SUPPORT) */
72 #if !defined(ASN_DISABLE_UPER_SUPPORT)
73 per_type_decoder_f INTEGER_decode_uper;
74 per_type_encoder_f INTEGER_encode_uper;
75 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) */
76 #if !defined(ASN_DISABLE_APER_SUPPORT)
77 per_type_decoder_f INTEGER_decode_aper;
78 per_type_encoder_f INTEGER_encode_aper;
79 #endif /* !defined(ASN_DISABLE_APER_SUPPORT) */
81 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
82 asn_random_fill_f INTEGER_random_fill;
83 #endif /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
85 /***********************************
86 * Some handy conversion routines. *
87 ***********************************/
90 * Natiwe size-independent conversion of native integers to/from INTEGER.
91 * (l_size) is in bytes.
92 * Returns 0 if it was possible to convert, -1 otherwise.
93 * -1/EINVAL: Mandatory argument missing
94 * -1/ERANGE: Value encoded is out of range for long representation
95 * -1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()).
97 int asn_INTEGER2imax(const INTEGER_t *i, intmax_t *l);
98 int asn_INTEGER2umax(const INTEGER_t *i, uintmax_t *l);
99 int asn_imax2INTEGER(INTEGER_t *i, intmax_t l);
100 int asn_umax2INTEGER(INTEGER_t *i, uintmax_t l);
103 * Size-specific conversion helpers.
105 int asn_INTEGER2long(const INTEGER_t *i, long *l);
106 int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
107 int asn_long2INTEGER(INTEGER_t *i, long l);
108 int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
109 int asn_int642INTEGER(INTEGER_t *i, int64_t l);
110 int asn_uint642INTEGER(INTEGER_t *i, uint64_t l);
112 /* A version of strtol/strtoimax(3) with nicer error reporting. */
113 enum asn_strtox_result_e {
114 ASN_STRTOX_ERROR_RANGE = -3, /* Input outside of supported numeric range */
115 ASN_STRTOX_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */
116 ASN_STRTOX_EXPECT_MORE = -1, /* More data expected (e.g. "+") */
117 ASN_STRTOX_OK = 0, /* Conversion succeeded, number ends at (*end) */
118 ASN_STRTOX_EXTRA_DATA = 1 /* Conversion succeeded, but the string has extra stuff */
120 enum asn_strtox_result_e asn_strtol_lim(const char *str, const char **end,
122 enum asn_strtox_result_e asn_strtoul_lim(const char *str, const char **end,
124 enum asn_strtox_result_e asn_strtoimax_lim(const char *str, const char **end,
126 enum asn_strtox_result_e asn_strtoumax_lim(const char *str, const char **end,
130 * Convert the integer value into the corresponding enumeration map entry.
132 const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(
133 const asn_INTEGER_specifics_t *specs, long value);
139 #endif /* _INTEGER_H_ */