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 29, 2017
1 parent daab1af commit 8ff07d2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
30 changes: 30 additions & 0 deletions skeletons/asn_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}

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
9 changes: 8 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,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[] = {
Expand All @@ -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),
Expand Down Expand Up @@ -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)" : "");
}
Expand Down

0 comments on commit 8ff07d2

Please sign in to comment.