3 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
9 #include <asn_application.h>
10 #include <asn_codecs_prim.h>
16 typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
18 extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
19 extern asn_TYPE_operation_t asn_OP_INTEGER;
21 /* Map with <tag> to integer value association */
22 typedef struct asn_INTEGER_enum_map_s {
23 long nat_value; /* associated native integer value */
24 size_t enum_len; /* strlen("tag") */
25 const char *enum_name; /* "tag" */
26 } asn_INTEGER_enum_map_t;
28 /* This type describes an enumeration for INTEGER and ENUMERATED types */
29 typedef struct asn_INTEGER_specifics_s {
30 const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
31 const unsigned int *enum2value; /* "tag" => N; sorted by tag */
32 int map_count; /* Elements in either map */
33 int extension; /* This map is extensible */
34 int strict_enumeration; /* Enumeration set is fixed */
35 int field_width; /* Size of native integer */
36 int field_unsigned; /* Signed=0, unsigned=1 */
37 } asn_INTEGER_specifics_t;
39 #define INTEGER_free ASN__PRIMITIVE_TYPE_free
40 #define INTEGER_decode_ber ber_decode_primitive
41 #define INTEGER_constraint asn_generic_no_constraint
42 asn_struct_print_f INTEGER_print;
43 asn_struct_compare_f INTEGER_compare;
44 der_type_encoder_f INTEGER_encode_der;
45 xer_type_decoder_f INTEGER_decode_xer;
46 xer_type_encoder_f INTEGER_encode_xer;
47 oer_type_decoder_f INTEGER_decode_oer;
48 oer_type_encoder_f INTEGER_encode_oer;
49 per_type_decoder_f INTEGER_decode_uper;
50 per_type_encoder_f INTEGER_encode_uper;
51 per_type_decoder_f INTEGER_decode_aper;
52 per_type_encoder_f INTEGER_encode_aper;
53 asn_random_fill_f INTEGER_random_fill;
55 /***********************************
56 * Some handy conversion routines. *
57 ***********************************/
60 * Natiwe size-independent conversion of native integers to/from INTEGER.
61 * (l_size) is in bytes.
62 * Returns 0 if it was possible to convert, -1 otherwise.
63 * -1/EINVAL: Mandatory argument missing
64 * -1/ERANGE: Value encoded is out of range for long representation
65 * -1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()).
67 int asn_INTEGER2imax(const INTEGER_t *i, intmax_t *l);
68 int asn_INTEGER2umax(const INTEGER_t *i, uintmax_t *l);
69 int asn_imax2INTEGER(INTEGER_t *i, intmax_t l);
70 int asn_umax2INTEGER(INTEGER_t *i, uintmax_t l);
73 * Size-specific conversion helpers.
75 int asn_INTEGER2long(const INTEGER_t *i, long *l);
76 int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
77 int asn_long2INTEGER(INTEGER_t *i, long l);
78 int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
79 int asn_int642INTEGER(INTEGER_t *i, int64_t l);
80 int asn_uint642INTEGER(INTEGER_t *i, uint64_t l);
82 /* A version of strtol/strtoimax(3) with nicer error reporting. */
83 enum asn_strtox_result_e {
84 ASN_STRTOX_ERROR_RANGE = -3, /* Input outside of supported numeric range */
85 ASN_STRTOX_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */
86 ASN_STRTOX_EXPECT_MORE = -1, /* More data expected (e.g. "+") */
87 ASN_STRTOX_OK = 0, /* Conversion succeded, number ends at (*end) */
88 ASN_STRTOX_EXTRA_DATA = 1 /* Conversion succeded, but the string has extra stuff */
90 enum asn_strtox_result_e asn_strtol_lim(const char *str, const char **end,
92 enum asn_strtox_result_e asn_strtoul_lim(const char *str, const char **end,
94 enum asn_strtox_result_e asn_strtoimax_lim(const char *str, const char **end,
96 enum asn_strtox_result_e asn_strtoumax_lim(const char *str, const char **end,
100 * Convert the integer value into the corresponding enumeration map entry.
102 const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(
103 const asn_INTEGER_specifics_t *specs, long value);
109 #endif /* _INTEGER_H_ */