ITS
INTEGER.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 #ifndef _INTEGER_H_
6 #define _INTEGER_H_
7 
8 #include <asn_application.h>
9 #include <asn_codecs_prim.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
16 
18 
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" */
25 
26 /* This type describes an enumeration for INTEGER and ENUMERATED types */
27 typedef struct asn_INTEGER_specifics_s {
28  asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
29  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 */
36 
44 
45 /***********************************
46  * Some handy conversion routines. *
47  ***********************************/
48 
49 /*
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()).
54  */
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);
59 
60 /* A a reified version of strtol(3) with nicer error reporting. */
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 */
67 };
68 enum asn_strtol_result_e asn_strtol_lim(const char *str, const char **end, long *l);
69 
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);
72 
73 /*
74  * Convert the integer value into the corresponding enumeration map entry.
75  */
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif /* _INTEGER_H_ */
int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l)
Definition: INTEGER.c:857
xer_type_decoder_f INTEGER_decode_xer
Definition: INTEGER.h:40
struct asn_INTEGER_specifics_s asn_INTEGER_specifics_t
asn_strtol_result_e
Definition: INTEGER.h:61
asn_dec_rval_t() ber_type_decoder_f(struct asn_codec_ctx_s *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, const void *buf_ptr, size_t size, int tag_mode)
Definition: ber_decoder.h:32
ber_type_decoder_f INTEGER_decode_ber
Definition: INTEGER.h:38
asn_enc_rval_t() per_type_encoder_f(struct asn_TYPE_descriptor_s *type_descriptor, asn_per_constraints_t *constraints, void *struct_ptr, asn_per_outp_t *per_output)
Definition: per_encoder.h:58
der_type_encoder_f INTEGER_encode_der
Definition: INTEGER.h:39
struct asn_INTEGER_enum_map_s asn_INTEGER_enum_map_t
asn_enc_rval_t() xer_type_encoder_f(struct asn_TYPE_descriptor_s *type_descriptor, void *struct_ptr, int ilevel, enum xer_encoder_flags_e xer_flags, asn_app_consume_bytes_f *consume_bytes_cb, void *app_key)
Definition: xer_encoder.h:46
const asn_INTEGER_enum_map_t * INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value)
Definition: INTEGER.c:282
per_type_encoder_f INTEGER_encode_uper
Definition: INTEGER.h:43
int asn_long2INTEGER(INTEGER_t *i, long l)
Definition: INTEGER.c:882
unsigned int * enum2value
Definition: INTEGER.h:29
int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l)
Definition: INTEGER.c:825
asn_enc_rval_t() der_type_encoder_f(struct asn_TYPE_descriptor_s *type_descriptor, void *struct_ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, void *app_key)
Definition: der_encoder.h:37
ASN__PRIMITIVE_TYPE_t INTEGER_t
Definition: INTEGER.h:15
int asn_INTEGER2long(const INTEGER_t *i, long *l)
Definition: INTEGER.c:765
asn_dec_rval_t() xer_type_decoder_f(asn_codec_ctx_t *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, const char *opt_mname, const void *buf_ptr, size_t size)
Definition: xer_decoder.h:29
xer_type_encoder_f INTEGER_encode_xer
Definition: INTEGER.h:41
asn_struct_print_f INTEGER_print
Definition: INTEGER.h:37
asn_dec_rval_t() per_type_decoder_f(asn_codec_ctx_t *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, asn_per_constraints_t *constraints, void **struct_ptr, asn_per_data_t *per_data)
Definition: per_decoder.h:45
enum asn_strtol_result_e asn_strtol_lim(const char *str, const char **end, long *l)
Definition: INTEGER.c:966
int() asn_struct_print_f(struct asn_TYPE_descriptor_s *type_descriptor, const void *struct_ptr, int level, asn_app_consume_bytes_f *callback, void *app_key)
Definition: constr_TYPE.h:63
const char * enum_name
Definition: INTEGER.h:23
enum asn_strtol_result_e asn_strtol(const char *str, const char *end, long *l)
Definition: INTEGER.c:940
asn_INTEGER_enum_map_t * value2enum
Definition: INTEGER.h:28
per_type_decoder_f INTEGER_decode_uper
Definition: INTEGER.h:42
asn_TYPE_descriptor_t asn_DEF_INTEGER
Definition: INTEGER.c:17