per_encoder.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*-
  2. * Copyright (c) 2006-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
  3. * Redistribution and modifications are permitted subject to BSD license.
  4. */
  5. #ifndef _PER_ENCODER_H_
  6. #define _PER_ENCODER_H_
  7. #include <asn_application.h>
  8. #include <per_support.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. struct asn_TYPE_descriptor_s; /* Forward declaration */
  13. /*
  14. * Unaligned PER encoder of any ASN.1 type. May be invoked by the application.
  15. * WARNING: This function returns the number of encoded bits in the .encoded
  16. * field of the return value. Use the following formula to convert to bytes:
  17. * bytes = ((.encoded + 7) / 8)
  18. */
  19. asn_enc_rval_t uper_encode(
  20. const struct asn_TYPE_descriptor_s *type_descriptor,
  21. const asn_per_constraints_t *constraints,
  22. const void *struct_ptr, /* Structure to be encoded */
  23. asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */
  24. void *app_key /* Arbitrary callback argument */
  25. );
  26. /*
  27. * A variant of uper_encode() which encodes data into the existing buffer
  28. * WARNING: This function returns the number of encoded bits in the .encoded
  29. * field of the return value.
  30. */
  31. asn_enc_rval_t uper_encode_to_buffer(
  32. const struct asn_TYPE_descriptor_s *type_descriptor,
  33. const asn_per_constraints_t *constraints,
  34. const void *struct_ptr, /* Structure to be encoded */
  35. void *buffer, /* Pre-allocated buffer */
  36. size_t buffer_size /* Initial buffer size (max) */
  37. );
  38. /*
  39. * A variant of uper_encode_to_buffer() which allocates buffer itself.
  40. * Returns the number of bytes in the buffer or -1 in case of failure.
  41. * WARNING: This function produces a "Production of the complete encoding",
  42. * with length of at least one octet. Contrast this to precise bit-packing
  43. * encoding of uper_encode() and uper_encode_to_buffer().
  44. */
  45. ssize_t uper_encode_to_new_buffer(
  46. const struct asn_TYPE_descriptor_s *type_descriptor,
  47. const asn_per_constraints_t *constraints,
  48. const void *struct_ptr, /* Structure to be encoded */
  49. void **buffer_r /* Buffer allocated and returned */
  50. );
  51. /*
  52. * Type of the generic PER encoder function.
  53. */
  54. typedef asn_enc_rval_t(per_type_encoder_f)(
  55. const struct asn_TYPE_descriptor_s *type_descriptor,
  56. const asn_per_constraints_t *constraints, const void *struct_ptr,
  57. asn_per_outp_t *per_output);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* _PER_ENCODER_H_ */