blob: 94177cf4e3a04e8c4d2c55c62db6a289888cdf60 [file] [log] [blame]
Lev Walkin523de9e2006-08-18 01:34:18 +00001/*-
Lev Walkin20696a42017-10-17 21:27:33 -07002 * Copyright (c) 2006-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkin523de9e2006-08-18 01:34:18 +00003 * 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.
Lev Walkin62258e22007-06-23 23:50:25 +000019 * 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)
Lev Walkin523de9e2006-08-18 01:34:18 +000022 */
Lev Walkin20696a42017-10-17 21:27:33 -070023asn_enc_rval_t uper_encode(
24 const struct asn_TYPE_descriptor_s *type_descriptor,
25 const void *struct_ptr, /* Structure to be encoded */
26 asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */
27 void *app_key /* Arbitrary callback argument */
Lev Walkin523de9e2006-08-18 01:34:18 +000028);
29
Lev Walkin62258e22007-06-23 23:50:25 +000030/*
31 * A variant of uper_encode() which encodes data into the existing buffer
32 * WARNING: This function returns the number of encoded bits in the .encoded
33 * field of the return value.
34 */
Lev Walkin523de9e2006-08-18 01:34:18 +000035asn_enc_rval_t uper_encode_to_buffer(
Lev Walkin20696a42017-10-17 21:27:33 -070036 const struct asn_TYPE_descriptor_s *type_descriptor,
37 const void *struct_ptr, /* Structure to be encoded */
38 void *buffer, /* Pre-allocated buffer */
39 size_t buffer_size /* Initial buffer size (max) */
Lev Walkin523de9e2006-08-18 01:34:18 +000040);
41
Lev Walkin62258e22007-06-23 23:50:25 +000042/*
43 * A variant of uper_encode_to_buffer() which allocates buffer itself.
44 * Returns the number of bytes in the buffer or -1 in case of failure.
45 * WARNING: This function produces a "Production of the complete encoding",
Lev Walkina2987ea2007-06-26 23:56:54 +000046 * with length of at least one octet. Contrast this to precise bit-packing
Lev Walkin62258e22007-06-23 23:50:25 +000047 * encoding of uper_encode() and uper_encode_to_buffer().
48 */
49ssize_t uper_encode_to_new_buffer(
Lev Walkin20696a42017-10-17 21:27:33 -070050 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 void **buffer_r /* Buffer allocated and returned */
Lev Walkin62258e22007-06-23 23:50:25 +000054);
Lev Walkin523de9e2006-08-18 01:34:18 +000055
56/*
57 * Type of the generic PER encoder function.
58 */
Lev Walkin20696a42017-10-17 21:27:33 -070059typedef asn_enc_rval_t(per_type_encoder_f)(
60 const struct asn_TYPE_descriptor_s *type_descriptor,
61 const asn_per_constraints_t *constraints, const void *struct_ptr,
62 asn_per_outp_t *per_output);
Lev Walkin523de9e2006-08-18 01:34:18 +000063
64#ifdef __cplusplus
65}
66#endif
67
68#endif /* _PER_ENCODER_H_ */