blob: 416efd9acbc00150dab2a07364201ca63e37fd33 [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 Walkin8e8078a2004-09-26 13:10:40 +000011typedef ASN__PRIMITIVE_TYPE_t INTEGER_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000012
Lev Walkin5e033762004-09-29 13:26:15 +000013extern asn_TYPE_descriptor_t asn_DEF_INTEGER;
Lev Walkinf15320b2004-06-03 03:38:44 +000014
Lev Walkine0b56e02005-02-25 12:10:27 +000015/* Map with <tag> to integer value association */
16typedef struct asn_INTEGER_enum_map_s {
17 long nat_value; /* associated native integer value */
18 size_t enum_len; /* strlen("tag") */
19 const char *enum_name; /* "tag" */
20} asn_INTEGER_enum_map_t;
21
22/* This type describes an enumeration for INTEGER and ENUMERATED types */
23typedef struct asn_INTEGER_specifics_s {
24 asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */
25 unsigned int *enum2value; /* "tag" => N; sorted by tag */
26 int map_count; /* Elements in either map */
27 int extensible; /* This map is extensible */
28 int strict_enumeration; /* Enumeration set is fixed */
29} asn_INTEGER_specifics_t;
30
Lev Walkina9cc46e2004-09-22 16:06:28 +000031asn_struct_print_f INTEGER_print;
Lev Walkinf15320b2004-06-03 03:38:44 +000032ber_type_decoder_f INTEGER_decode_ber;
33der_type_encoder_f INTEGER_encode_der;
Lev Walkind703ff42004-10-21 11:21:25 +000034xer_type_decoder_f INTEGER_decode_xer;
Lev Walkina9cc46e2004-09-22 16:06:28 +000035xer_type_encoder_f INTEGER_encode_xer;
Lev Walkinf15320b2004-06-03 03:38:44 +000036
37/***********************************
38 * Some handy conversion routines. *
39 ***********************************/
40
41/*
42 * Returns 0 if it was possible to convert, -1 otherwise.
43 * -1/EINVAL: Mandatory argument missing
44 * -1/ERANGE: Value encoded is out of range for long representation
Lev Walkind703ff42004-10-21 11:21:25 +000045 * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()).
Lev Walkinf15320b2004-06-03 03:38:44 +000046 */
Lev Walkin5e033762004-09-29 13:26:15 +000047int asn_INTEGER2long(const INTEGER_t *i, long *l);
Lev Walkind703ff42004-10-21 11:21:25 +000048int asn_long2INTEGER(INTEGER_t *i, long l);
Lev Walkinf15320b2004-06-03 03:38:44 +000049
Lev Walkinfc776432005-03-29 17:21:14 +000050/*
51 * Convert the integer value into the corresponding enumeration map entry.
52 */
53const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value);
54
Lev Walkinf15320b2004-06-03 03:38:44 +000055#endif /* _INTEGER_H_ */