vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
vlm | ed5f7fc | 2005-02-28 15:20:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #ifndef _INTEGER_H_ |
| 6 | #define _INTEGER_H_ |
| 7 | |
vlm | d157958 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 8 | #include <asn_application.h> |
vlm | a4799a6 | 2004-10-21 11:21:25 +0000 | [diff] [blame] | 9 | #include <asn_codecs_prim.h> |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 10 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
vlm | 6678cb1 | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 15 | typedef ASN__PRIMITIVE_TYPE_t INTEGER_t; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 16 | |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 17 | extern asn_TYPE_descriptor_t asn_DEF_INTEGER; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 18 | |
vlm | 80a4859 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 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; |
| 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 */ |
vlm | 337167e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 31 | int extension; /* This map is extensible */ |
vlm | 80a4859 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 32 | int strict_enumeration; /* Enumeration set is fixed */ |
| 33 | } asn_INTEGER_specifics_t; |
| 34 | |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 35 | asn_struct_print_f INTEGER_print; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 36 | ber_type_decoder_f INTEGER_decode_ber; |
| 37 | der_type_encoder_f INTEGER_encode_der; |
vlm | a4799a6 | 2004-10-21 11:21:25 +0000 | [diff] [blame] | 38 | xer_type_decoder_f INTEGER_decode_xer; |
vlm | 39ba4c4 | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 39 | xer_type_encoder_f INTEGER_encode_xer; |
vlm | 337167e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 40 | per_type_decoder_f INTEGER_decode_uper; |
vlm | 18dd82c | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 41 | per_type_encoder_f INTEGER_encode_uper; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 42 | |
| 43 | /*********************************** |
| 44 | * Some handy conversion routines. * |
| 45 | ***********************************/ |
| 46 | |
| 47 | /* |
| 48 | * Returns 0 if it was possible to convert, -1 otherwise. |
| 49 | * -1/EINVAL: Mandatory argument missing |
| 50 | * -1/ERANGE: Value encoded is out of range for long representation |
vlm | a4799a6 | 2004-10-21 11:21:25 +0000 | [diff] [blame] | 51 | * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()). |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 52 | */ |
vlm | ef6355b | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 53 | int asn_INTEGER2long(const INTEGER_t *i, long *l); |
vlm | a4799a6 | 2004-10-21 11:21:25 +0000 | [diff] [blame] | 54 | int asn_long2INTEGER(INTEGER_t *i, long l); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 55 | |
vlm | 5ec2fe1 | 2005-03-29 17:21:14 +0000 | [diff] [blame] | 56 | /* |
| 57 | * Convert the integer value into the corresponding enumeration map entry. |
| 58 | */ |
| 59 | const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value); |
| 60 | |
vlm | 3a41758 | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 61 | #ifdef __cplusplus |
| 62 | } |
| 63 | #endif |
| 64 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 65 | #endif /* _INTEGER_H_ */ |