blob: b615ef028650bc9b24399256f41b54af85e79fc4 [file] [log] [blame]
rajalakshmisv21b61dd2021-12-07 04:53:03 +00001/*-
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
8#include <asn_application.h>
9#include <per_support.h>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15struct asn_TYPE_descriptor_s; /* Forward declaration */
16
17/*
18 * Unaligned PER encoder of any ASN.1 type. May be invoked by the application.
19 * WARNING: This function returns the number of encoded bits in the .encoded
20 * field of the return value. Use the following formula to convert to bytes:
21 * bytes = ((.encoded + 7) / 8)
22 */
23asn_enc_rval_t uper_encode(
24 const struct asn_TYPE_descriptor_s *type_descriptor,
25 const asn_per_constraints_t *constraints,
26 const void *struct_ptr, /* Structure to be encoded */
27 asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */
28 void *app_key /* Arbitrary callback argument */
29);
30
31asn_enc_rval_t aper_encode(
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 asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */
36 void *app_key /* Arbitrary callback argument */
37);
38
39/*
40 * A variant of uper_encode() which encodes data into the existing buffer
41 * WARNING: This function returns the number of encoded bits in the .encoded
42 * field of the return value.
43 */
44asn_enc_rval_t uper_encode_to_buffer(
45 const struct asn_TYPE_descriptor_s *type_descriptor,
46 const asn_per_constraints_t *constraints,
47 const void *struct_ptr, /* Structure to be encoded */
48 void *buffer, /* Pre-allocated buffer */
49 size_t buffer_size /* Initial buffer size (max) */
50);
51
52asn_enc_rval_t aper_encode_to_buffer(
53 const struct asn_TYPE_descriptor_s *type_descriptor,
54 const asn_per_constraints_t *constraints,
55 const void *struct_ptr, /* Structure to be encoded */
56 void *buffer, /* Pre-allocated buffer */
57 size_t buffer_size /* Initial buffer size (max) */
58);
59/*
60 * A variant of uper_encode_to_buffer() which allocates buffer itself.
61 * Returns the number of bytes in the buffer or -1 in case of failure.
62 * WARNING: This function produces a "Production of the complete encoding",
63 * with length of at least one octet. Contrast this to precise bit-packing
64 * encoding of uper_encode() and uper_encode_to_buffer().
65 */
66ssize_t uper_encode_to_new_buffer(
67 const struct asn_TYPE_descriptor_s *type_descriptor,
68 const asn_per_constraints_t *constraints,
69 const void *struct_ptr, /* Structure to be encoded */
70 void **buffer_r /* Buffer allocated and returned */
71);
72
73ssize_t
74aper_encode_to_new_buffer(
75 const struct asn_TYPE_descriptor_s *td,
76 const asn_per_constraints_t *constraints,
77 const void *sptr,
78 void **buffer_r
79);
80
81/*
82 * Type of the generic PER encoder function.
83 */
84typedef asn_enc_rval_t(per_type_encoder_f)(
85 const struct asn_TYPE_descriptor_s *type_descriptor,
86 const asn_per_constraints_t *constraints, const void *struct_ptr,
87 asn_per_outp_t *per_output);
88
89#ifdef __cplusplus
90}
91#endif
92
93#endif /* _PER_ENCODER_H_ */