blob: 81c0d0c05c88c8a24ae0b2416abaaefb8dbe24a5 [file] [log] [blame]
Lev Walkina9cc46e2004-09-22 16:06:28 +00001/*-
2 * Copyright (c) 2004 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
Lev Walkin11c3e172004-09-24 21:00:50 +00008#include <asn_application.h>
Lev Walkina9cc46e2004-09-22 16:06:28 +00009
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkin5e033762004-09-29 13:26:15 +000014struct asn_TYPE_descriptor_s; /* Forward declaration */
Lev Walkina9cc46e2004-09-22 16:06:28 +000015
16/* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */
17enum xer_encoder_flags_e {
18 /* Mode of encoding */
19 XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */
Lev Walkin34ae9e32006-03-17 02:40:30 +000020 XER_F_CANONICAL = 0x02 /* Canonical XER (strict rules) */
Lev Walkina9cc46e2004-09-22 16:06:28 +000021};
22
23/*
24 * The XER encoder of any type. May be invoked by the application.
Lev Walkin28647742017-09-12 11:07:06 -070025 * Produces CANONICAL-XER and BASIC-XER depending on the (xer_flags).
Lev Walkina9cc46e2004-09-22 16:06:28 +000026 */
Lev Walkin5e033762004-09-29 13:26:15 +000027asn_enc_rval_t xer_encode(struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkina9cc46e2004-09-22 16:06:28 +000028 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/*
Lev Walkine4589f92017-07-25 09:31:33 -070035 * A helper function that uses XER encoding/decoding to verify that:
36 * - Both structures encode into the same BASIC XER.
37 * - Both resulting XER byte streams can be decoded back.
38 * - Both decoded structures encode into the same BASIC XER (round-trip).
39 * All of this verifies equivalence between structures and a round-trip.
40 * ARGUMENTS:
41 * (opt_debug_stream) - If specified, prints ongoing details.
42 */
43enum xer_equivalence_e {
44 XEQ_SUCCESS, /* The only completely positive return value */
45 XEQ_FAILURE, /* General failure */
46 XEQ_ENCODE1_FAILED, /* First sructure XER encoding failed */
47 XEQ_ENCODE2_FAILED, /* Second structure XER encoding failed */
48 XEQ_DIFFERENT, /* Structures encoded into different XER */
49 XEQ_DECODE_FAILED, /* Decode of the XER data failed */
50 XEQ_ROUND_TRIP_FAILED /* Bad round-trip */
51};
52enum xer_equivalence_e xer_equivalent(
53 struct asn_TYPE_descriptor_s *type_descriptor, void *struct1, void *struct2,
54 FILE *opt_debug_stream);
55
56/*
Lev Walkina9cc46e2004-09-22 16:06:28 +000057 * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
58 * output into the chosen file pointer.
59 * RETURN VALUES:
60 * 0: The structure is printed.
61 * -1: Problem printing the structure.
62 * WARNING: No sensible errno value is returned.
63 */
Lev Walkin5e033762004-09-29 13:26:15 +000064int xer_fprint(FILE *stream, struct asn_TYPE_descriptor_s *td, void *sptr);
Lev Walkina9cc46e2004-09-22 16:06:28 +000065
66/*
67 * Type of the generic XER encoder.
68 */
69typedef asn_enc_rval_t (xer_type_encoder_f)(
Lev Walkin5e033762004-09-29 13:26:15 +000070 struct asn_TYPE_descriptor_s *type_descriptor,
Lev Walkina9cc46e2004-09-22 16:06:28 +000071 void *struct_ptr, /* Structure to be encoded */
72 int ilevel, /* Level of indentation */
73 enum xer_encoder_flags_e xer_flags,
74 asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
75 void *app_key /* Arbitrary callback argument */
76 );
77
Lev Walkin21b41ac2005-07-24 09:03:44 +000078#ifdef __cplusplus
79}
80#endif
81
Lev Walkina9cc46e2004-09-22 16:06:28 +000082#endif /* _XER_ENCODER_H_ */