Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / ASN1c / xer_encoder.h
1 /*-
2  * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 #ifndef _XER_ENCODER_H_
6 #define _XER_ENCODER_H_
7
8 #include <asn_application.h>
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 struct asn_TYPE_descriptor_s;   /* Forward declaration */
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) */
20         XER_F_CANONICAL = 0x02  /* Canonical XER (strict rules) */
21 };
22
23 /*
24  * The XER encoder of any type. May be invoked by the application.
25  * Produces CANONICAL-XER and BASIC-XER depending on the (xer_flags).
26  */
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 );
33
34 /*
35  * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
36  * output into the chosen file pointer.
37  * RETURN VALUES:
38  *       0: The structure is printed.
39  *      -1: Problem printing the structure.
40  * WARNING: No sensible errno value is returned.
41  */
42 int xer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td,
43                const void *struct_ptr);
44
45 /*
46  * A helper function that uses XER encoding/decoding to verify that:
47  * - Both structures encode into the same BASIC XER.
48  * - Both resulting XER byte streams can be decoded back.
49  * - Both decoded structures encode into the same BASIC XER (round-trip).
50  * All of this verifies equivalence between structures and a round-trip.
51  * ARGUMENTS:
52  *  (opt_debug_stream)  - If specified, prints ongoing details.
53  */
54 enum xer_equivalence_e {
55     XEQ_SUCCESS,          /* The only completely positive return value */
56     XEQ_FAILURE,          /* General failure */
57     XEQ_ENCODE1_FAILED,   /* First sructure XER encoding failed */
58     XEQ_ENCODE2_FAILED,   /* Second structure XER encoding failed */
59     XEQ_DIFFERENT,        /* Structures encoded into different XER */
60     XEQ_DECODE_FAILED,    /* Decode of the XER data failed */
61     XEQ_ROUND_TRIP_FAILED /* Bad round-trip */
62 };
63 enum xer_equivalence_e xer_equivalent(
64     const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct1,
65     const void *struct2, FILE *opt_debug_stream);
66
67 /*
68  * Type of the generic XER encoder.
69  */
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 );
78
79 #ifdef __cplusplus
80 }
81 #endif
82
83 #endif  /* _XER_ENCODER_H_ */