Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved. |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | #ifndef _XER_ENCODER_H_ |
| 6 | #define _XER_ENCODER_H_ |
| 7 | |
Lev Walkin | 11c3e17 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 8 | #include <asn_application.h> |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 9 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 15 | |
| 16 | /* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */ |
| 17 | enum xer_encoder_flags_e { |
| 18 | /* Mode of encoding */ |
| 19 | XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */ |
Lev Walkin | 34ae9e3 | 2006-03-17 02:40:30 +0000 | [diff] [blame] | 20 | XER_F_CANONICAL = 0x02 /* Canonical XER (strict rules) */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
| 23 | /* |
| 24 | * The XER encoder of any type. May be invoked by the application. |
Lev Walkin | 2864774 | 2017-09-12 11:07:06 -0700 | [diff] [blame] | 25 | * Produces CANONICAL-XER and BASIC-XER depending on the (xer_flags). |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 26 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 27 | asn_enc_rval_t xer_encode(const struct asn_TYPE_descriptor_s *type_descriptor, |
| 28 | const void *struct_ptr, /* Structure to be encoded */ |
| 29 | enum xer_encoder_flags_e xer_flags, |
| 30 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 31 | void *app_key /* Arbitrary callback argument */ |
| 32 | ); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 33 | |
| 34 | /* |
Lev Walkin | e4589f9 | 2017-07-25 09:31:33 -0700 | [diff] [blame] | 35 | * A helper function that uses XER encoding/decoding to verify that: |
| 36 | * - Both structures encode into the same BASIC XER. |
| 37 | * - Both resulting XER byte streams can be decoded back. |
| 38 | * - Both decoded structures encode into the same BASIC XER (round-trip). |
| 39 | * All of this verifies equivalence between structures and a round-trip. |
| 40 | * ARGUMENTS: |
| 41 | * (opt_debug_stream) - If specified, prints ongoing details. |
| 42 | */ |
| 43 | enum xer_equivalence_e { |
| 44 | XEQ_SUCCESS, /* The only completely positive return value */ |
| 45 | XEQ_FAILURE, /* General failure */ |
| 46 | XEQ_ENCODE1_FAILED, /* First sructure XER encoding failed */ |
| 47 | XEQ_ENCODE2_FAILED, /* Second structure XER encoding failed */ |
| 48 | XEQ_DIFFERENT, /* Structures encoded into different XER */ |
| 49 | XEQ_DECODE_FAILED, /* Decode of the XER data failed */ |
| 50 | XEQ_ROUND_TRIP_FAILED /* Bad round-trip */ |
| 51 | }; |
| 52 | enum xer_equivalence_e xer_equivalent( |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 53 | const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct1, |
| 54 | const void *struct2, FILE *opt_debug_stream); |
Lev Walkin | e4589f9 | 2017-07-25 09:31:33 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 57 | * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC) |
| 58 | * output into the chosen file pointer. |
| 59 | * RETURN VALUES: |
| 60 | * 0: The structure is printed. |
| 61 | * -1: Problem printing the structure. |
| 62 | * WARNING: No sensible errno value is returned. |
| 63 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 64 | int xer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td, |
| 65 | const void *sptr); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Type of the generic XER encoder. |
| 69 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 70 | typedef asn_enc_rval_t(xer_type_encoder_f)( |
| 71 | const struct asn_TYPE_descriptor_s *type_descriptor, |
| 72 | const void *struct_ptr, /* Structure to be encoded */ |
| 73 | int ilevel, /* Level of indentation */ |
| 74 | enum xer_encoder_flags_e xer_flags, |
| 75 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ |
| 76 | void *app_key /* Arbitrary callback argument */ |
| 77 | ); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 78 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 79 | #ifdef __cplusplus |
| 80 | } |
| 81 | #endif |
| 82 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 83 | #endif /* _XER_ENCODER_H_ */ |