blob: 9aa5457fd8cbcf9dfe3c1a00f0f360cf19d184ff [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 */
Lev Walkin59b176e2005-11-26 11:25:14 +000031 int extension; /* This map is extensible */
Lev Walkine0b56e02005-02-25 12:10:27 +000032 int strict_enumeration; /* Enumeration set is fixed */
Lev Walkin8bb57a22007-12-03 13:41:36 +000033 int field_width; /* Size of native integer */
34 int field_unsigned; /* Signed=0, unsigned=1 */
Lev Walkine0b56e02005-02-25 12:10:27 +000035} asn_INTEGER_specifics_t;
36
Lev Walkina9cc46e2004-09-22 16:06:28 +000037asn_struct_print_f INTEGER_print;
Lev Walkinf15320b2004-06-03 03:38:44 +000038ber_type_decoder_f INTEGER_decode_ber;
39der_type_encoder_f INTEGER_encode_der;
Lev Walkind703ff42004-10-21 11:21:25 +000040xer_type_decoder_f INTEGER_decode_xer;
Lev Walkina9cc46e2004-09-22 16:06:28 +000041xer_type_encoder_f INTEGER_encode_xer;
Lev Walkin59b176e2005-11-26 11:25:14 +000042per_type_decoder_f INTEGER_decode_uper;
Lev Walkin523de9e2006-08-18 01:34:18 +000043per_type_encoder_f INTEGER_encode_uper;
Lev Walkinf15320b2004-06-03 03:38:44 +000044
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
Lev Walkind703ff42004-10-21 11:21:25 +000053 * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()).
Lev Walkinf15320b2004-06-03 03:38:44 +000054 */
Lev Walkin5e033762004-09-29 13:26:15 +000055int asn_INTEGER2long(const INTEGER_t *i, long *l);
Lev Walkin5c879db2007-11-06 06:23:31 +000056int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l);
Lev Walkind703ff42004-10-21 11:21:25 +000057int asn_long2INTEGER(INTEGER_t *i, long l);
Lev Walkin5c879db2007-11-06 06:23:31 +000058int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l);
Lev Walkinf15320b2004-06-03 03:38:44 +000059
Lev Walkinb3751942012-09-02 19:36:47 -070060/* A a reified version of strtol(3) with nicer error reporting. */
61int asn_strtol(const char *str, const char *end, long *l);
62
Lev Walkinfc776432005-03-29 17:21:14 +000063/*
64 * Convert the integer value into the corresponding enumeration map entry.
65 */
66const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value);
67
Lev Walkin21b41ac2005-07-24 09:03:44 +000068#ifdef __cplusplus
69}
70#endif
71
Lev Walkinf15320b2004-06-03 03:38:44 +000072#endif /* _INTEGER_H_ */