2 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #ifndef _JER_ENCODER_H_
6 #define _JER_ENCODER_H_
8 #include <asn_application.h>
14 struct asn_TYPE_descriptor_s; /* Forward declaration */
16 /* Flags used by the jer_encode() and (*jer_type_encoder_f), defined below
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.
22 enum jer_encoder_flags_e {
23 /* Mode of encoding */
24 JER_F = 0x01, /* JER (pretty-printing) */
28 * The JER encoder of any type. May be invoked by the application.
29 * Produces JER output.
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 */
38 * The variant of the above function which dumps the JER
39 * output into the chosen file pointer.
41 * 0: The structure is printed.
42 * -1: Problem printing the structure.
43 * WARNING: No sensible errno value is returned.
45 int jer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td,
46 const void *struct_ptr);
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.
55 * (opt_debug_stream) - If specified, prints ongoing details.
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 */
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);
71 * Type of the generic JER encoder.
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 */
86 #endif /* _JER_ENCODER_H_ */