2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <asn_codecs_prim.h>
12 * Decode the chunk of XML text encoding INTEGER.
14 static enum xer_pbd_rval
15 BOOLEAN__xer_body_decode(const asn_TYPE_descriptor_t *td, void *sptr,
16 const void *chunk_buf, size_t chunk_size) {
17 BOOLEAN_t *st = (BOOLEAN_t *)sptr;
18 const char *p = (const char *)chunk_buf;
22 if(chunk_size && p[0] == 0x3c /* '<' */) {
23 switch(xer_check_tag(chunk_buf, chunk_size, "false")) {
29 if(xer_check_tag(chunk_buf, chunk_size, "true") != XCT_BOTH)
30 return XPBD_BROKEN_ENCODING;
32 *st = 1; /* Or 0xff as in DER?.. */
35 return XPBD_BROKEN_ENCODING;
37 return XPBD_BODY_CONSUMED;
39 return XPBD_BROKEN_ENCODING;
45 BOOLEAN_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
46 const asn_TYPE_descriptor_t *td, void **sptr,
47 const char *opt_mname, const void *buf_ptr, size_t size) {
48 return xer_decode_primitive(opt_codec_ctx, td,
49 sptr, sizeof(BOOLEAN_t), opt_mname, buf_ptr, size,
50 BOOLEAN__xer_body_decode);
54 BOOLEAN_encode_xer(const asn_TYPE_descriptor_t *td, const void *sptr,
55 int ilevel, enum xer_encoder_flags_e flags,
56 asn_app_consume_bytes_f *cb, void *app_key) {
57 const BOOLEAN_t *st = (const BOOLEAN_t *)sptr;
58 asn_enc_rval_t er = {0, 0, 0};
63 if(!st) ASN__ENCODE_FAILED;
66 ASN__CALLBACK("<true/>", 7);
68 ASN__CALLBACK("<false/>", 8);