b36257a242920d62a3533e91e4de05bd223a311e
[ric-plt/resource-status-manager.git] / RSM / 3rdparty / asn1codec / e2ap_engine / per_encoder.h
1
2 /*-
3  * Copyright (c) 2006-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef _PER_ENCODER_H_
7 #define _PER_ENCODER_H_
8
9 #include <asn_application.h>
10 #include <per_support.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 struct asn_TYPE_descriptor_s;   /* Forward declaration */
17
18 /*
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)
23  */
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 */
30 );
31
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 */
38 );
39
40 /*
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.
44  */
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) */
51 );
52
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) */
59 );
60 /*
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().
66  */
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 */
72 );
73
74 ssize_t
75 aper_encode_to_new_buffer(
76     const struct asn_TYPE_descriptor_s *td,
77     const asn_per_constraints_t *constraints,
78     const void *sptr,
79     void **buffer_r
80 );
81
82 /*
83  * Type of the generic PER encoder function.
84  */
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);
89
90 #ifdef __cplusplus
91 }
92 #endif
93
94 #endif  /* _PER_ENCODER_H_ */