X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8e80bb9cec2c90dd61f810fb1525932a434288eb..0c097ef3435d2a45c1ee4ac80f8bd3f254fb8df5:/libs/smux/include/stg/INTEGER.h?ds=sidebyside diff --git a/libs/smux/include/stg/INTEGER.h b/libs/smux/include/stg/INTEGER.h index 9a880970..cc760ffa 100644 --- a/libs/smux/include/stg/INTEGER.h +++ b/libs/smux/include/stg/INTEGER.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003, 2005 Lev Walkin . All rights reserved. + * Copyright (c) 2003-2017 Lev Walkin . All rights reserved. * Redistribution and modifications are permitted subject to BSD license. */ #ifndef _INTEGER_H_ @@ -15,6 +15,7 @@ extern "C" { typedef ASN__PRIMITIVE_TYPE_t INTEGER_t; extern asn_TYPE_descriptor_t asn_DEF_INTEGER; +extern asn_TYPE_operation_t asn_OP_INTEGER; /* Map with to integer value association */ typedef struct asn_INTEGER_enum_map_s { @@ -24,7 +25,7 @@ typedef struct asn_INTEGER_enum_map_s { } asn_INTEGER_enum_map_t; /* This type describes an enumeration for INTEGER and ENUMERATED types */ -typedef const struct asn_INTEGER_specifics_s { +typedef struct asn_INTEGER_specifics_s { const asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ const unsigned int *enum2value; /* "tag" => N; sorted by tag */ int map_count; /* Elements in either map */ @@ -34,46 +35,67 @@ typedef const struct asn_INTEGER_specifics_s { int field_unsigned; /* Signed=0, unsigned=1 */ } asn_INTEGER_specifics_t; +#define INTEGER_free ASN__PRIMITIVE_TYPE_free +#define INTEGER_decode_ber ber_decode_primitive +#define INTEGER_constraint asn_generic_no_constraint asn_struct_print_f INTEGER_print; -ber_type_decoder_f INTEGER_decode_ber; +asn_struct_compare_f INTEGER_compare; der_type_encoder_f INTEGER_encode_der; xer_type_decoder_f INTEGER_decode_xer; xer_type_encoder_f INTEGER_encode_xer; +oer_type_decoder_f INTEGER_decode_oer; +oer_type_encoder_f INTEGER_encode_oer; per_type_decoder_f INTEGER_decode_uper; per_type_encoder_f INTEGER_encode_uper; +asn_random_fill_f INTEGER_random_fill; /*********************************** * Some handy conversion routines. * ***********************************/ /* + * Natiwe size-independent conversion of native integers to/from INTEGER. + * (l_size) is in bytes. * Returns 0 if it was possible to convert, -1 otherwise. * -1/EINVAL: Mandatory argument missing * -1/ERANGE: Value encoded is out of range for long representation - * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()). + * -1/ENOMEM: Memory allocation failed (in asn_*2INTEGER()). + */ +int asn_INTEGER2imax(const INTEGER_t *i, intmax_t *l); +int asn_INTEGER2umax(const INTEGER_t *i, uintmax_t *l); +int asn_imax2INTEGER(INTEGER_t *i, intmax_t l); +int asn_umax2INTEGER(INTEGER_t *i, uintmax_t l); + +/* + * Size-specific conversion helpers. */ int asn_INTEGER2long(const INTEGER_t *i, long *l); int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l); int asn_long2INTEGER(INTEGER_t *i, long l); int asn_ulong2INTEGER(INTEGER_t *i, unsigned long l); -/* A a reified version of strtol(3) with nicer error reporting. */ -enum asn_strtol_result_e { - ASN_STRTOL_ERROR_RANGE = -3, /* Input outside of numeric range for long type */ - ASN_STRTOL_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */ - ASN_STRTOL_EXPECT_MORE = -1, /* More data expected (e.g. "+") */ - ASN_STRTOL_OK = 0, /* Conversion succeded, number ends at (*end) */ - ASN_STRTOL_EXTRA_DATA = 1 /* Conversion succeded, but the string has extra stuff */ +/* A version of strtol/strtoimax(3) with nicer error reporting. */ +enum asn_strtox_result_e { + ASN_STRTOX_ERROR_RANGE = -3, /* Input outside of supported numeric range */ + ASN_STRTOX_ERROR_INVAL = -2, /* Invalid data encountered (e.g., "+-") */ + ASN_STRTOX_EXPECT_MORE = -1, /* More data expected (e.g. "+") */ + ASN_STRTOX_OK = 0, /* Conversion succeded, number ends at (*end) */ + ASN_STRTOX_EXTRA_DATA = 1 /* Conversion succeded, but the string has extra stuff */ }; -enum asn_strtol_result_e asn_strtol_lim(const char *str, const char **end, long *l); - -/* The asn_strtol is going to be DEPRECATED soon */ -enum asn_strtol_result_e asn_strtol(const char *str, const char *end, long *l); +enum asn_strtox_result_e asn_strtol_lim(const char *str, const char **end, + long *l); +enum asn_strtox_result_e asn_strtoul_lim(const char *str, const char **end, + unsigned long *l); +enum asn_strtox_result_e asn_strtoimax_lim(const char *str, const char **end, + intmax_t *l); +enum asn_strtox_result_e asn_strtoumax_lim(const char *str, const char **end, + uintmax_t *l); /* * Convert the integer value into the corresponding enumeration map entry. */ -const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value); +const asn_INTEGER_enum_map_t *INTEGER_map_value2enum( + const asn_INTEGER_specifics_t *specs, long value); #ifdef __cplusplus }