diff options
author | Lev Walkin <vlm@lionet.info> | 2004-10-21 14:13:48 +0000 |
---|---|---|
committer | Lev Walkin <vlm@lionet.info> | 2004-10-21 14:13:48 +0000 |
commit | 435cb289bd2ab2d1395a19c419dbbecd2319f3ed (patch) | |
tree | 439347c2c949d6f44e93e293eb8b14df6f86d7ae | |
parent | 8471ceca4fca4e738dde3773007bbe31ecbcc0c3 (diff) |
NativeInteger XER support
-rw-r--r-- | skeletons/NativeEnumerated.c | 2 | ||||
-rw-r--r-- | skeletons/NativeInteger.c | 50 | ||||
-rw-r--r-- | skeletons/NativeInteger.h | 1 |
3 files changed, 50 insertions, 3 deletions
diff --git a/skeletons/NativeEnumerated.c b/skeletons/NativeEnumerated.c index 191afb77..8a524853 100644 --- a/skeletons/NativeEnumerated.c +++ b/skeletons/NativeEnumerated.c @@ -26,7 +26,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = { asn_generic_no_constraint, NativeInteger_decode_ber, NativeInteger_encode_der, - 0, /* Not implemented yet */ + NativeInteger_decode_xer, NativeInteger_encode_xer, 0, /* Use generic outmost tag fetcher */ asn_DEF_NativeEnumerated_tags, diff --git a/skeletons/NativeInteger.c b/skeletons/NativeInteger.c index 695b9631..159d00d2 100644 --- a/skeletons/NativeInteger.c +++ b/skeletons/NativeInteger.c @@ -28,7 +28,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeInteger = { asn_generic_no_constraint, NativeInteger_decode_ber, NativeInteger_encode_der, - 0, /* Not implemented yet */ + NativeInteger_decode_xer, NativeInteger_encode_xer, 0, /* Use generic outmost tag fetcher */ asn_DEF_NativeInteger_tags, @@ -110,7 +110,7 @@ NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx, * This expression hopefully will be optimized away * by compiler. */ - if(sizeof(int) != sizeof(long) && (*Int != l)) { + if(sizeof(int) != sizeof(long) && ((long)*Int != l)) { *Int = 0; /* Safe value */ rval.code = RC_FAIL; rval.consumed = 0; @@ -164,6 +164,52 @@ NativeInteger_encode_der(asn_TYPE_descriptor_t *sd, void *ptr, return erval; } +/* + * Decode the chunk of XML text encoding INTEGER. + */ +asn_dec_rval_t +NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx, + asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname, + void *buf_ptr, size_t size) { + asn_dec_rval_t rval; + INTEGER_t *st = 0; + int *Int = (int *)*sptr; + + if(!Int) { + (void *)Int = *sptr = CALLOC(1, sizeof(int)); + if(!Int) { + rval.code = RC_FAIL; + rval.consumed = 0; + return rval; + } + } + + rval = INTEGER_decode_xer(opt_codec_ctx, td, (void **)&st, opt_mname, + buf_ptr, size); + if(rval.code == RC_OK) { + long l; + if(asn_INTEGER2long(st, &l)) { + rval.code = RC_FAIL; + rval.consumed = 0; + } else { + *Int = l; + + /* int might be shorter than long */ + if(sizeof(int) != sizeof(long) && ((long)*Int != l)) { + *Int = 0; /* Safe value */ + rval.code = RC_FAIL; + rval.consumed = 0; + return rval; + } + } + } else { + rval.consumed = 0; + } + asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, st, 0); + return rval; +} + + asn_enc_rval_t NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, int ilevel, enum xer_encoder_flags_e flags, diff --git a/skeletons/NativeInteger.h b/skeletons/NativeInteger.h index 4de0d66a..777f8e65 100644 --- a/skeletons/NativeInteger.h +++ b/skeletons/NativeInteger.h @@ -20,6 +20,7 @@ asn_struct_free_f NativeInteger_free; asn_struct_print_f NativeInteger_print; ber_type_decoder_f NativeInteger_decode_ber; der_type_encoder_f NativeInteger_encode_der; +xer_type_decoder_f NativeInteger_decode_xer; xer_type_encoder_f NativeInteger_encode_xer; #endif /* _NativeInteger_H_ */ |