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