Skip to content
Snippets Groups Projects
Commit 435cb289 authored by Lev Walkin's avatar Lev Walkin
Browse files

NativeInteger XER support

parent 8471ceca
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = { ...@@ -26,7 +26,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeEnumerated = {
asn_generic_no_constraint, asn_generic_no_constraint,
NativeInteger_decode_ber, NativeInteger_decode_ber,
NativeInteger_encode_der, NativeInteger_encode_der,
0, /* Not implemented yet */ NativeInteger_decode_xer,
NativeInteger_encode_xer, NativeInteger_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_NativeEnumerated_tags, asn_DEF_NativeEnumerated_tags,
......
...@@ -28,7 +28,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeInteger = { ...@@ -28,7 +28,7 @@ asn_TYPE_descriptor_t asn_DEF_NativeInteger = {
asn_generic_no_constraint, asn_generic_no_constraint,
NativeInteger_decode_ber, NativeInteger_decode_ber,
NativeInteger_encode_der, NativeInteger_encode_der,
0, /* Not implemented yet */ NativeInteger_decode_xer,
NativeInteger_encode_xer, NativeInteger_encode_xer,
0, /* Use generic outmost tag fetcher */ 0, /* Use generic outmost tag fetcher */
asn_DEF_NativeInteger_tags, asn_DEF_NativeInteger_tags,
...@@ -110,7 +110,7 @@ NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx, ...@@ -110,7 +110,7 @@ NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
* This expression hopefully will be optimized away * This expression hopefully will be optimized away
* by compiler. * by compiler.
*/ */
if(sizeof(int) != sizeof(long) && (*Int != l)) { if(sizeof(int) != sizeof(long) && ((long)*Int != l)) {
*Int = 0; /* Safe value */ *Int = 0; /* Safe value */
rval.code = RC_FAIL; rval.code = RC_FAIL;
rval.consumed = 0; rval.consumed = 0;
...@@ -164,6 +164,52 @@ NativeInteger_encode_der(asn_TYPE_descriptor_t *sd, void *ptr, ...@@ -164,6 +164,52 @@ NativeInteger_encode_der(asn_TYPE_descriptor_t *sd, void *ptr,
return erval; 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 asn_enc_rval_t
NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
int ilevel, enum xer_encoder_flags_e flags, int ilevel, enum xer_encoder_flags_e flags,
......
...@@ -20,6 +20,7 @@ asn_struct_free_f NativeInteger_free; ...@@ -20,6 +20,7 @@ asn_struct_free_f NativeInteger_free;
asn_struct_print_f NativeInteger_print; asn_struct_print_f NativeInteger_print;
ber_type_decoder_f NativeInteger_decode_ber; ber_type_decoder_f NativeInteger_decode_ber;
der_type_encoder_f NativeInteger_encode_der; der_type_encoder_f NativeInteger_encode_der;
xer_type_decoder_f NativeInteger_decode_xer;
xer_type_encoder_f NativeInteger_encode_xer; xer_type_encoder_f NativeInteger_encode_xer;
#endif /* _NativeInteger_H_ */ #endif /* _NativeInteger_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment