Skip to content

Commit c672a2c

Browse files
committed
BNER support: converter-example
1 parent a95763d commit c672a2c

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

skeletons/asn_application.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,28 @@ asn_encode_internal(const asn_codec_ctx_t *opt_codec_ctx,
374374
}
375375
break;
376376

377+
case ATS_BNER:
378+
#ifdef ASN_DISABLE_BNER_SUPPORT
379+
errno = ENOENT; /* BNER is not defined. */
380+
ASN__ENCODE_FAILED;
381+
break;
382+
#else
383+
if(td->op->bner_encoder) {
384+
er = bner_encode(td, sptr, callback, callback_key);
385+
if(er.encoded == -1) {
386+
if(er.failed_type && er.failed_type->op->bner_encoder) {
387+
errno = EBADF; /* Structure has incorrect form. */
388+
} else {
389+
errno = ENOENT; /* BNER is not defined for this type. */
390+
}
391+
}
392+
} else {
393+
errno = ENOENT; /* Transfer syntax is not defined for this type. */
394+
ASN__ENCODE_FAILED;
395+
}
396+
break;
397+
#endif /* ASN_DISABLE_BNER_SUPPORT */
398+
377399
default:
378400
errno = ENOENT;
379401
ASN__ENCODE_FAILED;
@@ -435,6 +457,14 @@ asn_decode(const asn_codec_ctx_t *opt_codec_ctx,
435457
case ATS_BASIC_XER:
436458
case ATS_CANONICAL_XER:
437459
return xer_decode(opt_codec_ctx, td, sptr, buffer, size);
460+
461+
case ATS_BNER:
462+
#ifdef ASN_DISABLE_BNER_SUPPORT
463+
errno = ENOENT;
464+
ASN__DECODE_FAILED;
465+
#else
466+
return bner_decode(opt_codec_ctx, td, sptr, buffer, size);
467+
#endif
438468
}
439469
}
440470

skeletons/asn_application.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ enum asn_transfer_syntax {
5757
* CANONICAL-XER is a more strict variant of BASIC-XER.
5858
*/
5959
ATS_BASIC_XER,
60-
ATS_CANONICAL_XER
60+
ATS_CANONICAL_XER,
61+
/*
62+
* ASHRAE 135:
63+
* BNER: BACnet Encoding Rules.
64+
*/
65+
ATS_BNER
6166
};
6267

6368
/*

skeletons/converter-example.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ ats_simple_name(enum asn_transfer_syntax syntax) {
126126
case ATS_UNALIGNED_BASIC_PER:
127127
case ATS_UNALIGNED_CANONICAL_PER:
128128
return "PER";
129+
case ATS_BNER:
130+
return "BNER";
129131
default:
130132
return "<?>";
131133
}
@@ -148,6 +150,8 @@ static syntax_selector input_encodings[] = {
148150
"Input is in Unaligned PER (Packed Encoding Rules)"},
149151
{"xer", ATS_BASIC_XER, CODEC_OFFSET(xer_decoder),
150152
"Input is in XER (XML Encoding Rules)"},
153+
{"bner", ATS_BNER, CODEC_OFFSET(bner_decoder),
154+
"Input is in BNER (BACnet Encoding Rules)"},
151155
{0, ATS_INVALID, 0, 0}};
152156

153157
static syntax_selector output_encodings[] = {
@@ -159,6 +163,8 @@ static syntax_selector output_encodings[] = {
159163
"Output as Unaligned PER (Packed Encoding Rules)"},
160164
{"xer", ATS_BASIC_XER, CODEC_OFFSET(xer_encoder),
161165
"Output as XER (XML Encoding Rules)"},
166+
{"bner", ATS_BNER, CODEC_OFFSET(bner_encoder),
167+
"Output as BNER (BACnet Encoding Rules)"},
162168
{"text", ATS_NONSTANDARD_PLAINTEXT, CODEC_OFFSET(print_struct),
163169
"Output as plain semi-structured text"},
164170
{"null", ATS_INVALID, CODEC_OFFSET(print_struct),
@@ -355,7 +361,8 @@ main(int ac, char *av[]) {
355361
fprintf(stderr, "Where options are:\n");
356362
for(sel = input_encodings; sel->name; sel++) {
357363
if(ats_by_name(sel->name, anyPduType, sel)) {
358-
fprintf(stderr, " -i%s %s%s\n", sel->name,
364+
fprintf(stderr, " -i%s%s %s%s\n", sel->name,
365+
strlen(sel->name) > 3 ? "" : " ",
359366
sel->full_name,
360367
(sel->syntax == isyntax) ? " (DEFAULT)" : "");
361368
}

0 commit comments

Comments
 (0)