Moving in e2sim originally from it/test/simulators
[sim/e2-interface.git] / e2sim / ASN1c / xer_encoder.h
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 #                                                                            *
5 # Licensed under the Apache License, Version 2.0 (the "License");            *
6 # you may not use this file except in compliance with the License.           *
7 # You may obtain a copy of the License at                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
11 # Unless required by applicable law or agreed to in writing, software        *
12 # distributed under the License is distributed on an "AS IS" BASIS,          *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
14 # See the License for the specific language governing permissions and        *
15 # limitations under the License.                                             *
16 #                                                                            *
17 ******************************************************************************/
18
19 /*-
20  * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21  * Redistribution and modifications are permitted subject to BSD license.
22  */
23 #ifndef _XER_ENCODER_H_
24 #define _XER_ENCODER_H_
25
26 #include <asn_application.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 struct asn_TYPE_descriptor_s;   /* Forward declaration */
33
34 /* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */
35 enum xer_encoder_flags_e {
36         /* Mode of encoding */
37         XER_F_BASIC     = 0x01, /* BASIC-XER (pretty-printing) */
38         XER_F_CANONICAL = 0x02  /* Canonical XER (strict rules) */
39 };
40
41 /*
42  * The XER encoder of any type. May be invoked by the application.
43  * Produces CANONICAL-XER and BASIC-XER depending on the (xer_flags).
44  */
45 asn_enc_rval_t xer_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
46                           const void *struct_ptr, /* Structure to be encoded */
47                           enum xer_encoder_flags_e xer_flags,
48                           asn_app_consume_bytes_f *consume_bytes_cb,
49                           void *app_key /* Arbitrary callback argument */
50 );
51
52 /*
53  * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
54  * output into the chosen file pointer.
55  * RETURN VALUES:
56  *       0: The structure is printed.
57  *      -1: Problem printing the structure.
58  * WARNING: No sensible errno value is returned.
59  */
60 int xer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td,
61                const void *struct_ptr);
62
63 /*
64  * A helper function that uses XER encoding/decoding to verify that:
65  * - Both structures encode into the same BASIC XER.
66  * - Both resulting XER byte streams can be decoded back.
67  * - Both decoded structures encode into the same BASIC XER (round-trip).
68  * All of this verifies equivalence between structures and a round-trip.
69  * ARGUMENTS:
70  *  (opt_debug_stream)  - If specified, prints ongoing details.
71  */
72 enum xer_equivalence_e {
73     XEQ_SUCCESS,          /* The only completely positive return value */
74     XEQ_FAILURE,          /* General failure */
75     XEQ_ENCODE1_FAILED,   /* First sructure XER encoding failed */
76     XEQ_ENCODE2_FAILED,   /* Second structure XER encoding failed */
77     XEQ_DIFFERENT,        /* Structures encoded into different XER */
78     XEQ_DECODE_FAILED,    /* Decode of the XER data failed */
79     XEQ_ROUND_TRIP_FAILED /* Bad round-trip */
80 };
81 enum xer_equivalence_e xer_equivalent(
82     const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct1,
83     const void *struct2, FILE *opt_debug_stream);
84
85 /*
86  * Type of the generic XER encoder.
87  */
88 typedef asn_enc_rval_t(xer_type_encoder_f)(
89     const struct asn_TYPE_descriptor_s *type_descriptor,
90     const void *struct_ptr, /* Structure to be encoded */
91     int ilevel,             /* Level of indentation */
92     enum xer_encoder_flags_e xer_flags,
93     asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
94     void *app_key                              /* Arbitrary callback argument */
95 );
96
97 #ifdef __cplusplus
98 }
99 #endif
100
101 #endif  /* _XER_ENCODER_H_ */