2 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
5 #include <asn_internal.h>
6 #include <asn_codecs_prim.h>
8 #include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
11 * NULL basic type description.
13 static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
14 (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
16 asn_TYPE_operation_t asn_OP_NULL = {
20 BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
21 NULL_encode_der, /* Special handling of DER encoding */
24 #ifdef ASN_DISABLE_OER_SUPPORT
30 #endif /* ASN_DISABLE_OER_SUPPORT */
31 #ifdef ASN_DISABLE_PER_SUPPORT
37 NULL_decode_uper, /* Unaligned PER decoder */
38 NULL_encode_uper, /* Unaligned PER encoder */
39 NULL_decode_aper, /* Aligned PER decoder */
40 NULL_encode_aper, /* Aligned PER encoder */
41 #endif /* ASN_DISABLE_PER_SUPPORT */
43 0 /* Use generic outmost tag fetcher */
45 asn_TYPE_descriptor_t asn_DEF_NULL = {
50 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
51 asn_DEF_NULL_tags, /* Same as above */
52 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
53 { 0, 0, asn_generic_no_constraint },
54 0, 0, /* No members */
59 NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode,
60 ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
61 asn_enc_rval_t erval = {0,0,0};
63 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
64 if(erval.encoded == -1) {
65 erval.failed_type = td;
66 erval.structure_ptr = ptr;
69 ASN__ENCODED_OK(erval);
73 NULL_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
74 enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb,
76 asn_enc_rval_t er = {0,0,0};
85 /* XMLNullValue is empty */
91 static enum xer_pbd_rval
92 NULL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
93 const void *chunk_buf, size_t chunk_size) {
96 (void)chunk_buf; /* Going to be empty according to the rules below. */
99 * There must be no content in self-terminating <NULL/> tag.
102 return XPBD_BROKEN_ENCODING;
104 return XPBD_BODY_CONSUMED;
108 NULL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
109 const asn_TYPE_descriptor_t *td, void **sptr,
110 const char *opt_mname, const void *buf_ptr, size_t size) {
111 return xer_decode_primitive(opt_codec_ctx, td,
112 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
113 NULL__xer_body_decode);
117 NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) {
125 NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
126 asn_app_consume_bytes_f *cb, void *app_key) {
127 (void)td; /* Unused argument */
128 (void)ilevel; /* Unused argument */
131 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
133 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
137 #ifndef ASN_DISABLE_OER_SUPPORT
140 NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
141 const asn_TYPE_descriptor_t *td,
142 const asn_oer_constraints_t *constraints, void **sptr,
143 const void *ptr, size_t size) {
144 asn_dec_rval_t rv = {RC_OK, 0};
152 *sptr = MALLOC(sizeof(NULL_t));
154 *(NULL_t *)*sptr = 0;
164 NULL_encode_oer(const asn_TYPE_descriptor_t *td,
165 const asn_oer_constraints_t *constraints, const void *sptr,
166 asn_app_consume_bytes_f *cb, void *app_key) {
167 asn_enc_rval_t er = {0,0,0};
175 er.encoded = 0; /* Encoding in 0 bytes. */
180 #endif /* ASN_DISABLE_OER_SUPPORT */
182 #ifndef ASN_DISABLE_PER_SUPPORT
185 NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
186 const asn_TYPE_descriptor_t *td,
187 const asn_per_constraints_t *constraints, void **sptr,
188 asn_per_data_t *pd) {
197 *sptr = MALLOC(sizeof(NULL_t));
199 *(NULL_t *)*sptr = 0;
206 * NULL type does not have content octets.
215 NULL_encode_uper(const asn_TYPE_descriptor_t *td,
216 const asn_per_constraints_t *constraints, const void *sptr,
217 asn_per_outp_t *po) {
218 asn_enc_rval_t er = {0,0,0};
230 NULL_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
231 const asn_TYPE_descriptor_t *td,
232 const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
233 asn_dec_rval_t rv = {RC_OK, 0};
241 *sptr = MALLOC(sizeof(NULL_t));
243 *(NULL_t *)*sptr = 0;
250 * NULL type does not have content octets.
260 NULL_encode_aper(const asn_TYPE_descriptor_t *td,
261 const asn_per_constraints_t *constraints,
262 const void *sptr, asn_per_outp_t *po) {
263 asn_enc_rval_t er = {0,0,0};
274 #endif /* ASN_DISABLE_PER_SUPPORT */
276 asn_random_fill_result_t
277 NULL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
278 const asn_encoding_constraints_t *constr,
280 asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
281 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
282 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
288 if(max_length == 0) return result_skipped;
291 st = (NULL_t *)(*sptr = CALLOC(1, sizeof(*st)));
293 return result_failed;