introduce generic encoder
diff --git a/skeletons/asn_application.h b/skeletons/asn_application.h
index 71e9ba6..0a24018 100644
--- a/skeletons/asn_application.h
+++ b/skeletons/asn_application.h
@@ -16,14 +16,101 @@
#endif
/*
+ * A selection of ASN.1 Transfer Syntaxes to use with generalized
+ * encoder and decoders declared further in this .h file.
+ */
+enum asn_transfer_syntax {
+ /* Avoid appearance of a default transfer syntax. */
+ ATS_INVALID = 0,
+ /* Plaintext output, useful for debugging. */
+ ATS_NONSTANDARD_PLAINTEXT,
+ /*
+ * X.690:
+ * BER: Basic Encoding Rules.
+ * DER: Distinguished Encoding Rules.
+ * CER: Canonical Encoding Rules.
+ * DER and CER are more strict variants of BER.
+ */
+ ATS_BER,
+ ATS_DER,
+ ATS_CER, /* Only decoding is supported */
+ /*
+ * X.696:
+ * OER: Octet Encoding Rules.
+ * CANONICAL-OER is a more strict variant of BASIC-OER.
+ */
+ ATS_BASIC_OER,
+ ATS_CANONICAL_OER,
+ /*
+ * X.691:
+ * PER: Packed Encoding Rules.
+ * CANONICAL-PER is a more strict variant of BASIC-PER.
+ * NOTE: Produces or consumes a complete encoding (X.691 (08/2015) #11.1).
+ */
+ ATS_UNALIGNED_BASIC_PER,
+ ATS_UNALIGNED_CANONICAL_PER,
+ /*
+ * X.693:
+ * XER: XML Encoding Rules.
+ * CANONICAL-XER is a more strict variant of BASIC-XER.
+ */
+ ATS_BASIC_XER,
+ ATS_CANONICAL_XER,
+};
+
+/*
+ * A generic encoder for any supported transfer syntax.
+ * RETURN VALUES:
+ * The (.encoded) field of the return value is REDEFINED to mean the following:
+ * >=0: The computed size of the encoded data. Can exceed the (buffer_size).
+ * -1: Error encoding the structure. See the error code in (errno):
+ * EINVAL: Incorrect parameters to the function, such as NULLs.
+ * ENOENT: Encoding transfer syntax is not defined (for this type).
+ * EBADF: The structure has invalid form or content constraint failed.
+ * The (.failed_type) and (.structure_ptr) MIGHT be set to the appropriate
+ * values at the place of failure, if at all possible.
+ * WARNING: The (.encoded) field of the return value can exceed the buffer_size.
+ * This is similar to snprintf(3) contract which might return values
+ * greater than the buffer size.
+ */
+asn_enc_rval_t asn_encode_to_buffer(
+ const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */
+ enum asn_transfer_syntax,
+ struct asn_TYPE_descriptor_s *type_to_encode,
+ void *structure_to_encode,
+ void *buffer, size_t buffer_size);
+
+
+/*
* Generic type of an application-defined callback to return various
* types of data to the application.
* EXPECTED RETURN VALUES:
* -1: Failed to consume bytes. Abort the mission.
* Non-negative return values indicate success, and ignored.
*/
-typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size,
- void *application_specific_key);
+typedef int(asn_app_consume_bytes_f)(const void *buffer, size_t size,
+ void *application_specific_key);
+
+
+/*
+ * A generic encoder for any supported transfer syntax.
+ * Returns the comprehensive encoding result descriptor (see asn_codecs.h).
+ * RETURN VALUES:
+ * The negative (.encoded) field of the return values is accompanied with the
+ * following error codes (errno):
+ * EINVAL: Incorrect parameters to the function, such as NULLs.
+ * ENOENT: Encoding transfer syntax is not defined (for this type).
+ * EBADF: The structure has invalid form or content constraint failed.
+ * EIO: The (callback) has returned negative value during encoding.
+ */
+asn_enc_rval_t asn_encode(
+ const asn_codec_ctx_t *opt_codec_parameters, /* See asn_codecs.h */
+ enum asn_transfer_syntax,
+ struct asn_TYPE_descriptor_s *type_to_encode,
+ void *structure_to_encode,
+ asn_app_consume_bytes_f *callback, void *callback_key);
+
+
/*
* A callback of this type is called whenever constraint validation fails
@@ -38,6 +125,7 @@
const void *structure_which_failed_ptr,
const char *error_message_format, ...) GCC_PRINTFLIKE(4, 5);
+
#ifdef __cplusplus
}
#endif