Skip to content

Commit

Permalink
BNER support: converter-example
Browse files Browse the repository at this point in the history
  • Loading branch information
ringlej committed Nov 19, 2017
1 parent dae3e5c commit 72ed265
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
29 changes: 29 additions & 0 deletions skeletons/asn_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}

7 changes: 6 additions & 1 deletion skeletons/asn_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/*
Expand Down
13 changes: 12 additions & 1 deletion skeletons/converter-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<?>";
}
Expand All @@ -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[] = {
Expand All @@ -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),
Expand Down Expand Up @@ -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)" : "");
}
Expand Down

0 comments on commit 72ed265

Please sign in to comment.