Moving in e2sim originally from it/test/simulators
[sim/e2-interface.git] / e2sim / ASN1c / per_encoder.h
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 #                                                                            *
5 # Licensed under the Apache License, Version 2.0 (the "License");            *
6 # you may not use this file except in compliance with the License.           *
7 # You may obtain a copy of the License at                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
11 # Unless required by applicable law or agreed to in writing, software        *
12 # distributed under the License is distributed on an "AS IS" BASIS,          *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
14 # See the License for the specific language governing permissions and        *
15 # limitations under the License.                                             *
16 #                                                                            *
17 ******************************************************************************/
18
19 /*-
20  * Copyright (c) 2006-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21  * Redistribution and modifications are permitted subject to BSD license.
22  */
23 #ifndef _PER_ENCODER_H_
24 #define _PER_ENCODER_H_
25
26 #include <asn_application.h>
27 #include <per_support.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 struct asn_TYPE_descriptor_s;   /* Forward declaration */
34
35 /*
36  * Unaligned PER encoder of any ASN.1 type. May be invoked by the application.
37  * WARNING: This function returns the number of encoded bits in the .encoded
38  * field of the return value. Use the following formula to convert to bytes:
39  *      bytes = ((.encoded + 7) / 8)
40  */
41 asn_enc_rval_t uper_encode(
42     const struct asn_TYPE_descriptor_s *type_descriptor,
43     const asn_per_constraints_t *constraints,
44     const void *struct_ptr,                    /* Structure to be encoded */
45     asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */
46     void *app_key                              /* Arbitrary callback argument */
47 );
48
49 asn_enc_rval_t aper_encode(
50     const struct asn_TYPE_descriptor_s *type_descriptor,
51     const asn_per_constraints_t *constraints,
52     const void *struct_ptr,                     /* Structure to be encoded */
53     asn_app_consume_bytes_f *consume_bytes_cb,  /* Data collector */
54     void *app_key                               /* Arbitrary callback argument */
55 );
56
57 /*
58  * A variant of uper_encode() which encodes data into the existing buffer
59  * WARNING: This function returns the number of encoded bits in the .encoded
60  * field of the return value.
61  */
62 asn_enc_rval_t uper_encode_to_buffer(
63     const struct asn_TYPE_descriptor_s *type_descriptor,
64     const asn_per_constraints_t *constraints,
65     const void *struct_ptr, /* Structure to be encoded */
66     void *buffer,           /* Pre-allocated buffer */
67     size_t buffer_size      /* Initial buffer size (max) */
68 );
69
70 asn_enc_rval_t aper_encode_to_buffer(
71     const struct asn_TYPE_descriptor_s *type_descriptor,
72     const asn_per_constraints_t *constraints,
73     const void *struct_ptr,  /* Structure to be encoded */
74     void *buffer,            /* Pre-allocated buffer */
75     size_t buffer_size       /* Initial buffer size (max) */
76 );
77 /*
78  * A variant of uper_encode_to_buffer() which allocates buffer itself.
79  * Returns the number of bytes in the buffer or -1 in case of failure.
80  * WARNING: This function produces a "Production of the complete encoding",
81  * with length of at least one octet. Contrast this to precise bit-packing
82  * encoding of uper_encode() and uper_encode_to_buffer().
83  */
84 ssize_t uper_encode_to_new_buffer(
85     const struct asn_TYPE_descriptor_s *type_descriptor,
86     const asn_per_constraints_t *constraints,
87     const void *struct_ptr, /* Structure to be encoded */
88     void **buffer_r         /* Buffer allocated and returned */
89 );
90
91 ssize_t
92 aper_encode_to_new_buffer(
93     const struct asn_TYPE_descriptor_s *td,
94     const asn_per_constraints_t *constraints,
95     const void *sptr,
96     void **buffer_r
97 );
98
99 /*
100  * Type of the generic PER encoder function.
101  */
102 typedef asn_enc_rval_t(per_type_encoder_f)(
103     const struct asn_TYPE_descriptor_s *type_descriptor,
104     const asn_per_constraints_t *constraints, const void *struct_ptr,
105     asn_per_outp_t *per_output);
106
107 #ifdef __cplusplus
108 }
109 #endif
110
111 #endif  /* _PER_ENCODER_H_ */