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_descriptor_t asn_DEF_NULL = {
21 asn_generic_no_constraint,
22 BOOLEAN_decode_ber, /* Implemented in terms of BOOLEAN */
23 NULL_encode_der, /* Special handling of DER encoding */
26 NULL_decode_uper, /* Unaligned PER decoder */
27 NULL_encode_uper, /* Unaligned PER encoder */
28 0, /* Use generic outmost tag fetcher */
30 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
31 asn_DEF_NULL_tags, /* Same as above */
32 sizeof(asn_DEF_NULL_tags) / sizeof(asn_DEF_NULL_tags[0]),
33 0, /* No PER visible constraints */
34 0, 0, /* No members */
39 NULL_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
40 int tag_mode, ber_tlv_tag_t tag,
41 asn_app_consume_bytes_f *cb, void *app_key) {
44 erval.encoded = der_write_tags(td, 0, tag_mode, 0, tag, cb, app_key);
45 if(erval.encoded == -1) {
46 erval.failed_type = td;
47 erval.structure_ptr = ptr;
50 ASN__ENCODED_OK(erval);
54 NULL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
55 int ilevel, enum xer_encoder_flags_e flags,
56 asn_app_consume_bytes_f *cb, void *app_key) {
66 /* XMLNullValue is empty */
72 static enum xer_pbd_rval
73 NULL__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, const void *chunk_buf, size_t chunk_size) {
76 (void)chunk_buf; /* Going to be empty according to the rules below. */
79 * There must be no content in self-terminating <NULL/> tag.
82 return XPBD_BROKEN_ENCODING;
84 return XPBD_BODY_CONSUMED;
88 NULL_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
89 asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
90 const void *buf_ptr, size_t size) {
92 return xer_decode_primitive(opt_codec_ctx, td,
93 sptr, sizeof(NULL_t), opt_mname, buf_ptr, size,
94 NULL__xer_body_decode);
98 NULL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
99 asn_app_consume_bytes_f *cb, void *app_key) {
101 (void)td; /* Unused argument */
102 (void)ilevel; /* Unused argument */
105 return (cb("<present>", 9, app_key) < 0) ? -1 : 0;
107 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
112 NULL_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
113 asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
122 *sptr = MALLOC(sizeof(NULL_t));
124 *(NULL_t *)*sptr = 0;
131 * NULL type does not have content octets.
140 NULL_encode_uper(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
141 void *sptr, asn_per_outp_t *po) {