Skip to content

Commit 72ed265

Browse files
committed
BNER support: converter-example
1 parent dae3e5c commit 72ed265

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

skeletons/asn_application.c

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

377+
case ATS_BNER:
378+
#ifdef ASN_ENABLE_BNER_SUPPORT
379+
if(td->op->bner_encoder) {
380+
er = bner_encode(td, sptr, callback, callback_key);
381+
if(er.encoded == -1) {
382+
if(er.failed_type && er.failed_type->op->bner_encoder) {
383+
errno = EBADF; /* Structure has incorrect form. */
384+
} else {
385+
errno = ENOENT; /* BNER is not defined for this type. */
386+
}
387+
}
388+
} else {
389+
errno = ENOENT; /* Transfer syntax is not defined for this type. */
390+
ASN__ENCODE_FAILED;
391+
}
392+
#else
393+
errno = ENOENT;
394+
ASN__ENCODE_FAILED;
395+
#endif
396+
break;
397+
377398
default:
378399
errno = ENOENT;
379400
ASN__ENCODE_FAILED;
@@ -435,6 +456,14 @@ asn_decode(const asn_codec_ctx_t *opt_codec_ctx,
435456
case ATS_BASIC_XER:
436457
case ATS_CANONICAL_XER:
437458
return xer_decode(opt_codec_ctx, td, sptr, buffer, size);
459+
460+
case ATS_BNER:
461+
#ifdef ASN_ENABLE_BNER_SUPPORT
462+
return bner_decode(opt_codec_ctx, td, sptr, buffer, size);
463+
#else
464+
errno = ENOENT;
465+
ASN__DECODE_FAILED;
466+
#endif
438467
}
439468
}
440469

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: 12 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,10 @@ 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+
#ifdef ASN_ENABLE_BNER_SUPPORT
154+
{"bner", ATS_BNER, CODEC_OFFSET(bner_decoder),
155+
"Input is in BNER (BACnet Encoding Rules)"},
156+
#endif
151157
{0, ATS_INVALID, 0, 0}};
152158

153159
static syntax_selector output_encodings[] = {
@@ -159,6 +165,10 @@ static syntax_selector output_encodings[] = {
159165
"Output as Unaligned PER (Packed Encoding Rules)"},
160166
{"xer", ATS_BASIC_XER, CODEC_OFFSET(xer_encoder),
161167
"Output as XER (XML Encoding Rules)"},
168+
#ifdef ASN_ENABLE_BNER_SUPPORT
169+
{"bner", ATS_BNER, CODEC_OFFSET(bner_encoder),
170+
"Output as BNER (BACnet Encoding Rules)"},
171+
#endif
162172
{"text", ATS_NONSTANDARD_PLAINTEXT, CODEC_OFFSET(print_struct),
163173
"Output as plain semi-structured text"},
164174
{"null", ATS_INVALID, CODEC_OFFSET(print_struct),
@@ -355,7 +365,8 @@ main(int ac, char *av[]) {
355365
fprintf(stderr, "Where options are:\n");
356366
for(sel = input_encodings; sel->name; sel++) {
357367
if(ats_by_name(sel->name, anyPduType, sel)) {
358-
fprintf(stderr, " -i%s %s%s\n", sel->name,
368+
fprintf(stderr, " -i%s%s %s%s\n", sel->name,
369+
strlen(sel->name) > 3 ? "" : " ",
359370
sel->full_name,
360371
(sel->syntax == isyntax) ? " (DEFAULT)" : "");
361372
}

0 commit comments

Comments
 (0)