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