From c672a2cfb89026e918570f5ac2d4b7664a4e5dae Mon Sep 17 00:00:00 2001 From: Jon Ringle Date: Tue, 21 Nov 2017 09:39:14 -0500 Subject: [PATCH] BNER support: converter-example --- skeletons/asn_application.c | 30 ++++++++++++++++++++++++++++++ skeletons/asn_application.h | 7 ++++++- skeletons/converter-example.c | 9 ++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/skeletons/asn_application.c b/skeletons/asn_application.c index 8ce0261b8..4c6ef8c2c 100644 --- a/skeletons/asn_application.c +++ b/skeletons/asn_application.c @@ -374,6 +374,28 @@ asn_encode_internal(const asn_codec_ctx_t *opt_codec_ctx, } break; + case ATS_BNER: +#ifdef ASN_DISABLE_BNER_SUPPORT + errno = ENOENT; /* BNER is not defined. */ + ASN__ENCODE_FAILED; + break; +#else + 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; + } + break; +#endif /* ASN_DISABLE_BNER_SUPPORT */ + default: errno = ENOENT; ASN__ENCODE_FAILED; @@ -435,6 +457,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_DISABLE_BNER_SUPPORT + errno = ENOENT; + ASN__DECODE_FAILED; +#else + return bner_decode(opt_codec_ctx, td, sptr, buffer, size); +#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..b89b96034 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,8 @@ 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)"}, + {"bner", ATS_BNER, CODEC_OFFSET(bner_decoder), + "Input is in BNER (BACnet Encoding Rules)"}, {0, ATS_INVALID, 0, 0}}; static syntax_selector output_encodings[] = { @@ -159,6 +163,8 @@ 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)"}, + {"bner", ATS_BNER, CODEC_OFFSET(bner_encoder), + "Output as BNER (BACnet Encoding Rules)"}, {"text", ATS_NONSTANDARD_PLAINTEXT, CODEC_OFFSET(print_struct), "Output as plain semi-structured text"}, {"null", ATS_INVALID, CODEC_OFFSET(print_struct), @@ -355,7 +361,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)" : ""); }