oer_encoder.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
  3. * Redistribution and modifications are permitted subject to BSD license.
  4. */
  5. #ifndef OER_ENCODER_H
  6. #define OER_ENCODER_H
  7. #include <asn_application.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct asn_TYPE_descriptor_s; /* Forward declaration */
  12. /*
  13. * The Octet Encoding Rules (OER, X.696 08/2015) encoder for any type.
  14. * This function may be invoked directly by the application.
  15. * Produces CANONICAL-OER output compatible with CANONICAL-OER
  16. * and BASIC-OER decoders.
  17. */
  18. asn_enc_rval_t oer_encode(const struct asn_TYPE_descriptor_s *type_descriptor,
  19. const void *struct_ptr, /* Structure to be encoded */
  20. asn_app_consume_bytes_f *consume_bytes_cb,
  21. void *app_key /* Arbitrary callback argument */
  22. );
  23. /* A variant of oer_encode() which encodes data into the pre-allocated buffer */
  24. asn_enc_rval_t oer_encode_to_buffer(
  25. const struct asn_TYPE_descriptor_s *type_descriptor,
  26. const asn_oer_constraints_t *constraints,
  27. const void *struct_ptr, /* Structure to be encoded */
  28. void *buffer, /* Pre-allocated buffer */
  29. size_t buffer_size /* Initial buffer size (maximum) */
  30. );
  31. /*
  32. * Type of the generic OER encoder.
  33. */
  34. typedef asn_enc_rval_t(oer_type_encoder_f)(
  35. const struct asn_TYPE_descriptor_s *type_descriptor,
  36. const asn_oer_constraints_t *constraints,
  37. const void *struct_ptr, /* Structure to be encoded */
  38. asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */
  39. void *app_key /* Arbitrary callback argument */
  40. );
  41. /*
  42. * Write out the Open Type (X.696 (08/2015), #30).
  43. * RETURN VALUES:
  44. * -1: Fatal error encoding the type.
  45. * >0: Number of bytes serialized.
  46. */
  47. ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td,
  48. const asn_oer_constraints_t *constraints,
  49. const void *struct_ptr,
  50. asn_app_consume_bytes_f *consume_bytes_cb,
  51. void *app_key);
  52. /*
  53. * Length-prefixed buffer encoding for primitive types.
  54. */
  55. oer_type_encoder_f oer_encode_primitive;
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /* OER_ENCODER_H */