blob: 165c055f3b1561cc199845e023175fec728ab00b [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin4ca03ac2005-02-28 15:20:27 +00002 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _INTEGER_H_
6#define _INTEGER_H_
7
Lev Walkin11c3e172004-09-24 21:00:50 +00008#include <asn_application.h>
Lev Walkind703ff42004-10-21 11:21:25 +00009#include <asn_codecs_prim.h>
Lev Walkinf15320b2004-06-03 03:38:44 +000010
Lev Walkin21b41ac2005-07-24 09:03:44 +000011#ifdef __cplusplus
12extern "C" {
13#endif
14
Lev Walkin8e8078a2004-09-26 13:10:40 +000015typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000016
Lev Walkin5e033762004-09-29 13:26:15 +000017extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
Lev Walkinf15320b2004-06-03 03:38:44 +000018
Lev Walkine0b56e02005-02-25 12:10:27 +000019/* Map with <tag> to integer value association */
20typedef 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 */
27typedef 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 extensible; /* This map is extensible */
32 int strict_enumeration; /* Enumeration set is fixed */
33} asn_INTEGER_specifics_t;
34
Lev Walkina9cc46e2004-09-22 16:06:28 +000035asn_struct_print_f INTEGER_print;
Lev Walkinf15320b2004-06-03 03:38:44 +000036ber_type_decoder_f INTEGER_decode_ber;
37der_type_encoder_f INTEGER_encode_der;
Lev Walkind703ff42004-10-21 11:21:25 +000038xer_type_decoder_f INTEGER_decode_xer;
Lev Walkina9cc46e2004-09-22 16:06:28 +000039xer_type_encoder_f INTEGER_encode_xer;
Lev Walkinf15320b2004-06-03 03:38:44 +000040
41/***********************************
42 * Some handy conversion routines. *
43 ***********************************/
44
45/*
46 * Returns 0 if it was possible to convert, -1 otherwise.
47 * -1/EINVAL: Mandatory argument missing
48 * -1/ERANGE: Value encoded is out of range for long representation
Lev Walkind703ff42004-10-21 11:21:25 +000049 * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()).
Lev Walkinf15320b2004-06-03 03:38:44 +000050 */
Lev Walkin5e033762004-09-29 13:26:15 +000051int asn_INTEGER2long(const INTEGER_t *i, long *l);
Lev Walkind703ff42004-10-21 11:21:25 +000052int asn_long2INTEGER(INTEGER_t *i, long l);
Lev Walkinf15320b2004-06-03 03:38:44 +000053
Lev Walkinfc776432005-03-29 17:21:14 +000054/*
55 * Convert the integer value into the corresponding enumeration map entry.
56 */
57const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value);
58
Lev Walkin21b41ac2005-07-24 09:03:44 +000059#ifdef __cplusplus
60}
61#endif
62
Lev Walkinf15320b2004-06-03 03:38:44 +000063#endif /* _INTEGER_H_ */