SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / jer_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 _JER_ENCODER_H_
6 #define _JER_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 jer_encode() and (*jer_type_encoder_f), defined below
17  *
18  * This isn't actually used, it might be used in the future to support
19  * both normal JSON and prettified JSON output or removed.
20  * It came from XER
21  */
22 enum jer_encoder_flags_e {
23         /* Mode of encoding */
24         JER_F   = 0x01, /* JER (pretty-printing) */
25 };
26
27 /*
28  * The JER encoder of any type. May be invoked by the application.
29  * Produces JER output.
30  */
31 asn_enc_rval_t jer_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
32                           const void *struct_ptr, /* Structure to be encoded */
33                           asn_app_consume_bytes_f *consume_bytes_cb,
34                           void *app_key /* Arbitrary callback argument */
35 );
36
37 /*
38  * The variant of the above function which dumps the JER
39  * output into the chosen file pointer.
40  * RETURN VALUES:
41  *       0: The structure is printed.
42  *      -1: Problem printing the structure.
43  * WARNING: No sensible errno value is returned.
44  */
45 int jer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td,
46                const void *struct_ptr);
47
48 /*
49  * A helper function that uses JER encoding/decoding to verify that:
50  * - Both structures encode into the same JER.
51  * - Both resulting JER byte streams can be decoded back.
52  * - Both decoded structures encode into the same JER (round-trip).
53  * All of this verifies equivalence between structures and a round-trip.
54  * ARGUMENTS:
55  *  (opt_debug_stream)  - If specified, prints ongoing details.
56  */
57 enum jer_equivalence_e {
58     JEQ_SUCCESS,          /* The only completely positive return value */
59     JEQ_FAILURE,          /* General failure */
60     JEQ_ENCODE1_FAILED,   /* First structure JER encoding failed */
61     JEQ_ENCODE2_FAILED,   /* Second structure JER encoding failed */
62     JEQ_DIFFERENT,        /* Structures encoded into different JER */
63     JEQ_DECODE_FAILED,    /* Decode of the JER data failed */
64     JEQ_ROUND_TRIP_FAILED /* Bad round-trip */
65 };
66 enum jer_equivalence_e jer_equivalent(
67     const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct1,
68     const void *struct2, FILE *opt_debug_stream);
69
70 /*
71  * Type of the generic JER encoder.
72  */
73 typedef asn_enc_rval_t(jer_type_encoder_f)(
74     const struct asn_TYPE_descriptor_s *type_descriptor,
75     const void *struct_ptr, /* Structure to be encoded */
76     int ilevel,             /* Level of indentation */
77     enum jer_encoder_flags_e jer_flags,
78     asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
79     void *app_key                              /* Arbitrary callback argument */
80 );
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif  /* _JER_ENCODER_H_ */