Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2006-2017 Lev Walkin <vlm@lionet.info>. All rights reserved. |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 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 |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 16 | |
| 17 | /* |
| 18 | * Unaligned PER encoder of any ASN.1 type. May be invoked by the application. |
Lev Walkin | 62258e2 | 2007-06-23 23:50:25 +0000 | [diff] [blame] | 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) |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 22 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 23 | asn_enc_rval_t uper_encode( |
| 24 | const struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | 5615304 | 2017-10-24 00:47:03 -0700 | [diff] [blame] | 25 | const asn_per_constraints_t *constraints, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 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 */ |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 29 | ); |
| 30 | |
Lev Walkin | 62258e2 | 2007-06-23 23:50:25 +0000 | [diff] [blame] | 31 | /* |
| 32 | * A variant of uper_encode() which encodes data into the existing buffer |
| 33 | * WARNING: This function returns the number of encoded bits in the .encoded |
| 34 | * field of the return value. |
| 35 | */ |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 36 | asn_enc_rval_t uper_encode_to_buffer( |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 37 | const struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | 5615304 | 2017-10-24 00:47:03 -0700 | [diff] [blame] | 38 | const asn_per_constraints_t *constraints, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 39 | const void *struct_ptr, /* Structure to be encoded */ |
| 40 | void *buffer, /* Pre-allocated buffer */ |
| 41 | size_t buffer_size /* Initial buffer size (max) */ |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 42 | ); |
| 43 | |
Lev Walkin | 62258e2 | 2007-06-23 23:50:25 +0000 | [diff] [blame] | 44 | /* |
| 45 | * A variant of uper_encode_to_buffer() which allocates buffer itself. |
| 46 | * Returns the number of bytes in the buffer or -1 in case of failure. |
| 47 | * WARNING: This function produces a "Production of the complete encoding", |
Lev Walkin | a2987ea | 2007-06-26 23:56:54 +0000 | [diff] [blame] | 48 | * with length of at least one octet. Contrast this to precise bit-packing |
Lev Walkin | 62258e2 | 2007-06-23 23:50:25 +0000 | [diff] [blame] | 49 | * encoding of uper_encode() and uper_encode_to_buffer(). |
| 50 | */ |
| 51 | ssize_t uper_encode_to_new_buffer( |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 52 | const struct asn_TYPE_descriptor_s *type_descriptor, |
| 53 | const asn_per_constraints_t *constraints, |
| 54 | const void *struct_ptr, /* Structure to be encoded */ |
| 55 | void **buffer_r /* Buffer allocated and returned */ |
Lev Walkin | 62258e2 | 2007-06-23 23:50:25 +0000 | [diff] [blame] | 56 | ); |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * Type of the generic PER encoder function. |
| 60 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 61 | typedef asn_enc_rval_t(per_type_encoder_f)( |
| 62 | const struct asn_TYPE_descriptor_s *type_descriptor, |
| 63 | const asn_per_constraints_t *constraints, const void *struct_ptr, |
| 64 | asn_per_outp_t *per_output); |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 65 | |
| 66 | #ifdef __cplusplus |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | #endif /* _PER_ENCODER_H_ */ |