Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 5 | #ifndef OER_ENCODER_H |
| 6 | #define OER_ENCODER_H |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 7 | |
| 8 | #include <asn_application.h> |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | struct asn_TYPE_descriptor_s; /* Forward declaration */ |
| 15 | |
| 16 | /* |
| 17 | * The Octet Encoding Rules (OER, X.696 08/2015) encoder for any type. |
| 18 | * This function may be invoked directly by the application. |
Lev Walkin | 2864774 | 2017-09-12 11:07:06 -0700 | [diff] [blame] | 19 | * Produces CANONICAL-OER output compatible with CANONICAL-OER |
| 20 | * and BASIC-OER decoders. |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 21 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 22 | asn_enc_rval_t oer_encode(const struct asn_TYPE_descriptor_s *type_descriptor, |
| 23 | const void *struct_ptr, /* Structure to be encoded */ |
Lev Walkin | 4558ad0 | 2017-07-10 05:21:30 -0700 | [diff] [blame] | 24 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 25 | void *app_key /* Arbitrary callback argument */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 26 | ); |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 27 | |
| 28 | /* A variant of oer_encode() which encodes data into the pre-allocated buffer */ |
| 29 | asn_enc_rval_t oer_encode_to_buffer( |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 30 | const struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 31 | const asn_oer_constraints_t *constraints, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 32 | const void *struct_ptr, /* Structure to be encoded */ |
| 33 | void *buffer, /* Pre-allocated buffer */ |
| 34 | size_t buffer_size /* Initial buffer size (maximum) */ |
| 35 | ); |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Type of the generic OER encoder. |
| 39 | */ |
Lev Walkin | 4558ad0 | 2017-07-10 05:21:30 -0700 | [diff] [blame] | 40 | typedef asn_enc_rval_t(oer_type_encoder_f)( |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 41 | const struct asn_TYPE_descriptor_s *type_descriptor, |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 42 | const asn_oer_constraints_t *constraints, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 43 | const void *struct_ptr, /* Structure to be encoded */ |
Lev Walkin | 4558ad0 | 2017-07-10 05:21:30 -0700 | [diff] [blame] | 44 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ |
| 45 | void *app_key /* Arbitrary callback argument */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 46 | ); |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 47 | |
Lev Walkin | 312795a | 2017-10-17 15:48:34 -0700 | [diff] [blame] | 48 | /* |
| 49 | * Write out the Open Type (X.696 (08/2015), #30). |
| 50 | * RETURN VALUES: |
| 51 | * -1: Fatal error encoding the type. |
| 52 | * >=0: Number of bytes serialized. |
| 53 | */ |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 54 | ssize_t oer_open_type_put(const struct asn_TYPE_descriptor_s *td, |
Lev Walkin | 312795a | 2017-10-17 15:48:34 -0700 | [diff] [blame] | 55 | const asn_oer_constraints_t *constraints, |
Lev Walkin | 20696a4 | 2017-10-17 21:27:33 -0700 | [diff] [blame] | 56 | const void *struct_ptr, |
Lev Walkin | 312795a | 2017-10-17 15:48:34 -0700 | [diff] [blame] | 57 | asn_app_consume_bytes_f *consume_bytes_cb, |
| 58 | void *app_key); |
| 59 | |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 60 | |
Lev Walkin | b5b524b | 2017-10-13 03:14:03 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Length-prefixed buffer encoding for primitive types. |
| 63 | */ |
| 64 | oer_type_encoder_f oer_encode_primitive; |
| 65 | |
Lev Walkin | cc15947 | 2017-07-06 08:26:36 -0700 | [diff] [blame] | 66 | #ifdef __cplusplus |
| 67 | } |
| 68 | #endif |
| 69 | |
Lev Walkin | d88bea9 | 2017-07-20 11:21:30 +0300 | [diff] [blame] | 70 | #endif /* OER_ENCODER_H */ |