From 72ed2658d083b96b04ea2e9e3db5669e087fd3a6 Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Sun, 19 Nov 2017 08:24:34 -0500 Subject: [PATCH] BNER support: converter-example --- skeletons/asn_application.c | 29 +++++++++++++++++++++++++++++ skeletons/asn_application.h | 7 ++++++- skeletons/converter-example.c | 13 ++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/skeletons/asn_application.c b/skeletons/asn_application.c index 8ce0261b8..95da7e767 100644 --- a/skeletons/asn_application.c +++ b/skeletons/asn_application.c @@ -374,6 +374,27 @@ asn_encode_internal(const asn_codec_ctx_t *opt_codec_ctx, } break; + case ATS_BNER: +#ifdef ASN_ENABLE_BNER_SUPPORT + if(td->op->bner_encoder) { + er = bner_encode(td, sptr, callback, callback_key); + if(er.encoded == -1) { + if(er.failed_type && er.failed_type->op->bner_encoder) { + errno = EBADF; /* Structure has incorrect form. */ + } else { + errno = ENOENT; /* BNER is not defined for this type. */ + } + } + } else { + errno = ENOENT; /* Transfer syntax is not defined for this type. */ + ASN__ENCODE_FAILED; + } +#else + errno = ENOENT; + ASN__ENCODE_FAILED; +#endif + break; + default: errno = ENOENT; ASN__ENCODE_FAILED; @@ -435,6 +456,14 @@ asn_decode(const asn_codec_ctx_t *opt_codec_ctx, case ATS_BASIC_XER: case ATS_CANONICAL_XER: return xer_decode(opt_codec_ctx, td, sptr, buffer, size); + + case ATS_BNER: +#ifdef ASN_ENABLE_BNER_SUPPORT + return bner_decode(opt_codec_ctx, td, sptr, buffer, size); +#else + errno = ENOENT; + ASN__DECODE_FAILED; +#endif } } diff --git a/skeletons/asn_application.h b/skeletons/asn_application.h index 3ca9f138e..2b38f299e 100644 --- a/skeletons/asn_application.h +++ b/skeletons/asn_application.h @@ -57,7 +57,12 @@ enum asn_transfer_syntax { * CANONICAL-XER is a more strict variant of BASIC-XER. */ ATS_BASIC_XER, - ATS_CANONICAL_XER + ATS_CANONICAL_XER, + /* + * ASHRAE 135: + * BNER: BACnet Encoding Rules. + */ + ATS_BNER }; /* diff --git a/skeletons/converter-example.c b/skeletons/converter-example.c index b54045250..d6b422c7c 100644 --- a/skeletons/converter-example.c +++ b/skeletons/converter-example.c @@ -126,6 +126,8 @@ ats_simple_name(enum asn_transfer_syntax syntax) { case ATS_UNALIGNED_BASIC_PER: case ATS_UNALIGNED_CANONICAL_PER: return "PER"; + case ATS_BNER: + return "BNER"; default: return ""; } @@ -148,6 +150,10 @@ static syntax_selector input_encodings[] = { "Input is in Unaligned PER (Packed Encoding Rules)"}, {"xer", ATS_BASIC_XER, CODEC_OFFSET(xer_decoder), "Input is in XER (XML Encoding Rules)"}, +#ifdef ASN_ENABLE_BNER_SUPPORT + {"bner", ATS_BNER, CODEC_OFFSET(bner_decoder), + "Input is in BNER (BACnet Encoding Rules)"}, +#endif {0, ATS_INVALID, 0, 0}}; static syntax_selector output_encodings[] = { @@ -159,6 +165,10 @@ static syntax_selector output_encodings[] = { "Output as Unaligned PER (Packed Encoding Rules)"}, {"xer", ATS_BASIC_XER, CODEC_OFFSET(xer_encoder), "Output as XER (XML Encoding Rules)"}, +#ifdef ASN_ENABLE_BNER_SUPPORT + {"bner", ATS_BNER, CODEC_OFFSET(bner_encoder), + "Output as BNER (BACnet Encoding Rules)"}, +#endif {"text", ATS_NONSTANDARD_PLAINTEXT, CODEC_OFFSET(print_struct), "Output as plain semi-structured text"}, {"null", ATS_INVALID, CODEC_OFFSET(print_struct), @@ -355,7 +365,8 @@ main(int ac, char *av[]) { fprintf(stderr, "Where options are:\n"); for(sel = input_encodings; sel->name; sel++) { if(ats_by_name(sel->name, anyPduType, sel)) { - fprintf(stderr, " -i%s %s%s\n", sel->name, + fprintf(stderr, " -i%s%s %s%s\n", sel->name, + strlen(sel->name) > 3 ? "" : " ", sel->full_name, (sel->syntax == isyntax) ? " (DEFAULT)" : ""); }