3 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #ifndef _XER_ENCODER_H_
7 #define _XER_ENCODER_H_
9 #include <asn_application.h>
15 struct asn_TYPE_descriptor_s; /* Forward declaration */
17 /* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */
18 enum xer_encoder_flags_e {
19 /* Mode of encoding */
20 XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */
21 XER_F_CANONICAL = 0x02 /* Canonical XER (strict rules) */
25 * The XER encoder of any type. May be invoked by the application.
26 * Produces CANONICAL-XER and BASIC-XER depending on the (xer_flags).
28 asn_enc_rval_t xer_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
29 const void *struct_ptr, /* Structure to be encoded */
30 enum xer_encoder_flags_e xer_flags,
31 asn_app_consume_bytes_f *consume_bytes_cb,
32 void *app_key /* Arbitrary callback argument */
36 * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
37 * output into the chosen file pointer.
39 * 0: The structure is printed.
40 * -1: Problem printing the structure.
41 * WARNING: No sensible errno value is returned.
43 int xer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td,
44 const void *struct_ptr);
47 * A helper function that uses XER encoding/decoding to verify that:
48 * - Both structures encode into the same BASIC XER.
49 * - Both resulting XER byte streams can be decoded back.
50 * - Both decoded structures encode into the same BASIC XER (round-trip).
51 * All of this verifies equivalence between structures and a round-trip.
53 * (opt_debug_stream) - If specified, prints ongoing details.
55 enum xer_equivalence_e {
56 XEQ_SUCCESS, /* The only completely positive return value */
57 XEQ_FAILURE, /* General failure */
58 XEQ_ENCODE1_FAILED, /* First sructure XER encoding failed */
59 XEQ_ENCODE2_FAILED, /* Second structure XER encoding failed */
60 XEQ_DIFFERENT, /* Structures encoded into different XER */
61 XEQ_DECODE_FAILED, /* Decode of the XER data failed */
62 XEQ_ROUND_TRIP_FAILED /* Bad round-trip */
64 enum xer_equivalence_e xer_equivalent(
65 const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct1,
66 const void *struct2, FILE *opt_debug_stream);
69 * Type of the generic XER encoder.
71 typedef asn_enc_rval_t(xer_type_encoder_f)(
72 const struct asn_TYPE_descriptor_s *type_descriptor,
73 const void *struct_ptr, /* Structure to be encoded */
74 int ilevel, /* Level of indentation */
75 enum xer_encoder_flags_e xer_flags,
76 asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
77 void *app_key /* Arbitrary callback argument */
84 #endif /* _XER_ENCODER_H_ */