xer_encoder.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 _XER_ENCODER_H_
  6. #define _XER_ENCODER_H_
  7. #include <asn_application.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct asn_TYPE_descriptor_s; /* Forward declaration */
  12. /* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */
  13. enum xer_encoder_flags_e {
  14. /* Mode of encoding */
  15. XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */
  16. XER_F_CANONICAL = 0x02 /* Canonical XER (strict rules) */
  17. };
  18. /*
  19. * The XER encoder of any type. May be invoked by the application.
  20. * Produces CANONICAL-XER and BASIC-XER depending on the (xer_flags).
  21. */
  22. asn_enc_rval_t xer_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
  23. const void *struct_ptr, /* Structure to be encoded */
  24. enum xer_encoder_flags_e xer_flags,
  25. asn_app_consume_bytes_f *consume_bytes_cb,
  26. void *app_key /* Arbitrary callback argument */
  27. );
  28. /*
  29. * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC)
  30. * output into the chosen file pointer.
  31. * RETURN VALUES:
  32. * 0: The structure is printed.
  33. * -1: Problem printing the structure.
  34. * WARNING: No sensible errno value is returned.
  35. */
  36. int xer_fprint(FILE *stream, const struct asn_TYPE_descriptor_s *td,
  37. const void *struct_ptr);
  38. /*
  39. * A helper function that uses XER encoding/decoding to verify that:
  40. * - Both structures encode into the same BASIC XER.
  41. * - Both resulting XER byte streams can be decoded back.
  42. * - Both decoded structures encode into the same BASIC XER (round-trip).
  43. * All of this verifies equivalence between structures and a round-trip.
  44. * ARGUMENTS:
  45. * (opt_debug_stream) - If specified, prints ongoing details.
  46. */
  47. enum xer_equivalence_e {
  48. XEQ_SUCCESS, /* The only completely positive return value */
  49. XEQ_FAILURE, /* General failure */
  50. XEQ_ENCODE1_FAILED, /* First sructure XER encoding failed */
  51. XEQ_ENCODE2_FAILED, /* Second structure XER encoding failed */
  52. XEQ_DIFFERENT, /* Structures encoded into different XER */
  53. XEQ_DECODE_FAILED, /* Decode of the XER data failed */
  54. XEQ_ROUND_TRIP_FAILED /* Bad round-trip */
  55. };
  56. enum xer_equivalence_e xer_equivalent(
  57. const struct asn_TYPE_descriptor_s *type_descriptor, const void *struct1,
  58. const void *struct2, FILE *opt_debug_stream);
  59. /*
  60. * Type of the generic XER encoder.
  61. */
  62. typedef asn_enc_rval_t(xer_type_encoder_f)(
  63. const struct asn_TYPE_descriptor_s *type_descriptor,
  64. const void *struct_ptr, /* Structure to be encoded */
  65. int ilevel, /* Level of indentation */
  66. enum xer_encoder_flags_e xer_flags,
  67. asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
  68. void *app_key /* Arbitrary callback argument */
  69. );
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif /* _XER_ENCODER_H_ */