3 * Copyright (c) 2006-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #ifndef _PER_ENCODER_H_
7 #define _PER_ENCODER_H_
9 #include <asn_application.h>
10 #include <per_support.h>
16 struct asn_TYPE_descriptor_s; /* Forward declaration */
19 * Unaligned PER encoder of any ASN.1 type. May be invoked by the application.
20 * WARNING: This function returns the number of encoded bits in the .encoded
21 * field of the return value. Use the following formula to convert to bytes:
22 * bytes = ((.encoded + 7) / 8)
24 asn_enc_rval_t uper_encode(
25 const struct asn_TYPE_descriptor_s *type_descriptor,
26 const asn_per_constraints_t *constraints,
27 const void *struct_ptr, /* Structure to be encoded */
28 asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */
29 void *app_key /* Arbitrary callback argument */
32 asn_enc_rval_t aper_encode(
33 const struct asn_TYPE_descriptor_s *type_descriptor,
34 const asn_per_constraints_t *constraints,
35 const void *struct_ptr, /* Structure to be encoded */
36 asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */
37 void *app_key /* Arbitrary callback argument */
41 * A variant of uper_encode() which encodes data into the existing buffer
42 * WARNING: This function returns the number of encoded bits in the .encoded
43 * field of the return value.
45 asn_enc_rval_t uper_encode_to_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, /* Pre-allocated buffer */
50 size_t buffer_size /* Initial buffer size (max) */
53 asn_enc_rval_t aper_encode_to_buffer(
54 const struct asn_TYPE_descriptor_s *type_descriptor,
55 const asn_per_constraints_t *constraints,
56 const void *struct_ptr, /* Structure to be encoded */
57 void *buffer, /* Pre-allocated buffer */
58 size_t buffer_size /* Initial buffer size (max) */
61 * A variant of uper_encode_to_buffer() which allocates buffer itself.
62 * Returns the number of bytes in the buffer or -1 in case of failure.
63 * WARNING: This function produces a "Production of the complete encoding",
64 * with length of at least one octet. Contrast this to precise bit-packing
65 * encoding of uper_encode() and uper_encode_to_buffer().
67 ssize_t uper_encode_to_new_buffer(
68 const struct asn_TYPE_descriptor_s *type_descriptor,
69 const asn_per_constraints_t *constraints,
70 const void *struct_ptr, /* Structure to be encoded */
71 void **buffer_r /* Buffer allocated and returned */
75 aper_encode_to_new_buffer(
76 const struct asn_TYPE_descriptor_s *td,
77 const asn_per_constraints_t *constraints,
83 * Type of the generic PER encoder function.
85 typedef asn_enc_rval_t(per_type_encoder_f)(
86 const struct asn_TYPE_descriptor_s *type_descriptor,
87 const asn_per_constraints_t *constraints, const void *struct_ptr,
88 asn_per_outp_t *per_output);
94 #endif /* _PER_ENCODER_H_ */