3 * Copyright (c) 2003, 2005 Lev Walkin <vlm@lionet.info>. All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <asn_codecs_prim.h>
9 #include <BOOLEAN.h> /* Implemented in terms of BOOLEAN type */
12 * NULL basic type description.
14 static const ber_tlv_tag_t asn_DEF_NULL_tags[] = {
15 (ASN_TAG_CLASS_UNIVERSAL | (5 << 2))
17 asn_TYPE_operation_t asn_OP_NULL = {
21 BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
22 NULL_encode_der, /* Special handling of DER encoding */
25 #ifdef ASN_DISABLE_OER_SUPPORT
31 #endif /* ASN_DISABLE_OER_SUPPORT */
32 #ifdef ASN_DISABLE_PER_SUPPORT
38 NULL_decode_uper, /* Unaligned PER decoder */
39 NULL_encode_uper, /* Unaligned PER encoder */
40 NULL_decode_aper, /* Aligned PER decoder */
41 NULL_encode_aper, /* Aligned PER encoder */
42 #endif /* ASN_DISABLE_PER_SUPPORT */
44 0 /* Use generic outmost tag fetcher */
46 asn_TYPE_descriptor_t asn_DEF_NULL = {
51 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
52 asn_DEF_NULL_tags, /* Same as above */
53 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
54 { 0, 0, asn_generic_no_constraint },
55 0, 0, /* No members */
60 NULL_encode_der(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode,
61 ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
62 asn_enc_rval_t erval = {0,0,0};
64 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
65 if(erval.encoded == -1) {
66 erval.failed_type = td;
67 erval.structure_ptr = ptr;
70 ASN__ENCODED_OK(erval);
74 NULL_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
75 enum xer_encoder_flags_e flags, asn_app_consume_bytes_f *cb,
77 asn_enc_rval_t er = {0,0,0};
86 /* XMLNullValue is empty */
92 static enum xer_pbd_rval
93 NULL__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
94 const void *chunk_buf, size_t chunk_size) {
97 (void)chunk_buf; /* Going to be empty according to the rules below. */
100 * There must be no content in self-terminating <NULL/> tag.
103 return XPBD_BROKEN_ENCODING;
105 return XPBD_BODY_CONSUMED;
109 NULL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
110 const asn_TYPE_descriptor_t *td, void **sptr,
111 const char *opt_mname, const void *buf_ptr, size_t size) {
112 return xer_decode_primitive(opt_codec_ctx, td,
113 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
114 NULL__xer_body_decode);
118 NULL_compare(const asn_TYPE_descriptor_t *td, const void *a, const void *b) {
126 NULL_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
127 asn_app_consume_bytes_f *cb, void *app_key) {
128 (void)td; /* Unused argument */
129 (void)ilevel; /* Unused argument */
132 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
134 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
138 #ifndef ASN_DISABLE_OER_SUPPORT
141 NULL_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
142 const asn_TYPE_descriptor_t *td,
143 const asn_oer_constraints_t *constraints, void **sptr,
144 const void *ptr, size_t size) {
145 asn_dec_rval_t rv = {RC_OK, 0};
153 *sptr = MALLOC(sizeof(NULL_t));
155 *(NULL_t *)*sptr = 0;
165 NULL_encode_oer(const asn_TYPE_descriptor_t *td,
166 const asn_oer_constraints_t *constraints, const void *sptr,
167 asn_app_consume_bytes_f *cb, void *app_key) {
168 asn_enc_rval_t er = {0,0,0};
176 er.encoded = 0; /* Encoding in 0 bytes. */
181 #endif /* ASN_DISABLE_OER_SUPPORT */
183 #ifndef ASN_DISABLE_PER_SUPPORT
186 NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
187 const asn_TYPE_descriptor_t *td,
188 const asn_per_constraints_t *constraints, void **sptr,
189 asn_per_data_t *pd) {
198 *sptr = MALLOC(sizeof(NULL_t));
200 *(NULL_t *)*sptr = 0;
207 * NULL type does not have content octets.
216 NULL_encode_uper(const asn_TYPE_descriptor_t *td,
217 const asn_per_constraints_t *constraints, const void *sptr,
218 asn_per_outp_t *po) {
219 asn_enc_rval_t er = {0,0,0};
231 NULL_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
232 const asn_TYPE_descriptor_t *td,
233 const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
234 asn_dec_rval_t rv = {RC_OK, 0};
242 *sptr = MALLOC(sizeof(NULL_t));
244 *(NULL_t *)*sptr = 0;
251 * NULL type does not have content octets.
261 NULL_encode_aper(const asn_TYPE_descriptor_t *td,
262 const asn_per_constraints_t *constraints,
263 const void *sptr, asn_per_outp_t *po) {
264 asn_enc_rval_t er = {0,0,0};
275 #endif /* ASN_DISABLE_PER_SUPPORT */
277 asn_random_fill_result_t
278 NULL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
279 const asn_encoding_constraints_t *constr,
281 asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
282 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
283 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
289 if(max_length == 0) return result_skipped;
292 st = (NULL_t *)(*sptr = CALLOC(1, sizeof(*st)));
294 return result_failed;