Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inital commit of Protobuf output #389

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ doc/docsrc/*.xdv
#code coverage
*.gcno
*.gcda

# Eclipse
.cproject
.project
.settings/

70 changes: 70 additions & 0 deletions README_ONF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Extracting protobuf from ASN.1

This project adds a -B option to output .proto files from ASN.1
(work in progress).

This approach generates protobufs like XSD is generated from asn1c.


For a very rudimentary conversion try:
```bash
./asn1c/asn1c -B examples/rectangle.asn
# Protobuf generated by asn1c-0.9.29 -->
# ASN.1 module RectangleModule from in examples/rectangle.asn

syntax = "proto3";

package e2ctypes;

message Rectangle {
int32 height = 1;
int32 width = 2;
}
```

For something a bit fancier try
```bash
./asn1c/asn1c -B examples/SeanModule.asn
# Protobuf generated by asn1c-0.9.29 -->
# ASN.1 module MyModule from in examples/SeanModule.asn

syntax = "proto3";

package e2ctypes;

message MyTypes {
BasicOid myObjectId = 1;
repeated TODO find reference mySeqOf = 2;
BitString myBitString = 3;
}

message MyInt {
int32 value = 1;
}
```

To go all out on the E2AP ASN.1 model try
```bash
./asn1c/asn1c -B examples/e2ap-v01.00.00.asn
WARNING: Parameterized type maxProtocolIEs expected for maxProtocolIEs at line 1543 in examples/e2ap-v01.00.00.asn
<repeated>
# Protobuf generated by asn1c-0.9.29 -->
# ASN.1 module E2AP-PDU-Descriptions { iso(1) identified-organization(3) dod(6) internet(1)
private(4) enterprise(1) 53148 e2(1) version1(1) e2ap(1)
e2ap-PDU-Descriptions(0) }
from in examples/e2ap-v01.00.00.asn

syntax = "proto3";

package e2ctypes;

message E2AP-ELEMENTARY-PROCEDURE {
&InitiatingMessage = 1;
&SuccessfulOutcome = 2;
&UnsuccessfulOutcome = 3;
&procedureCode = 4;
&criticality = 5;
}

...continues for 100s of lines
```
8 changes: 7 additions & 1 deletion asn1c/asn1c.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ main(int ac, char **av) {
/*
* Process command-line options.
*/
while((ch = getopt(ac, av, "D:d:EFf:g:hn:LPp:RS:vW:X")) != -1) switch(ch) {
while((ch = getopt(ac, av, "D:d:EFf:g:hn:LPp:RS:vW:XB")) != -1) switch(ch) {
case 'D':
if(optarg && *optarg) {
size_t optarg_len = strlen(optarg);
Expand Down Expand Up @@ -245,6 +245,11 @@ main(int ac, char **av) {
print_arg__fix_n_print = 1; /* Implicit -F */
asn1_printer_flags |= APF_PRINT_XML_DTD;
break;
case 'B':
print_arg__print_out = 1; /* Implicit -E */
print_arg__fix_n_print = 1; /* Implicit -F */
asn1_printer_flags |= APF_PRINT_PROTOBUF;
break;
default:
usage(av[0]);
}
Expand Down Expand Up @@ -545,6 +550,7 @@ usage(const char *av0) {
" (Default is \"%s\")\n"
" -D <dir> Destination directory for generated files (default current dir)\n"
" -X Generate and print the XML DTD\n"
" -B Generate and print the protoBuf\n"
"\n"

" -Werror Treat warnings as errors; abort if any warning\n"
Expand Down
3 changes: 3 additions & 0 deletions doc/man/asn1c.man.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ and other encoding rules.
-X
: Generate an XML DTD schema for the specified ASN.1 files.

-B
: Generate a Protobuf definition for the specified ASN.1 files.

## Warning Options

-Werror
Expand Down
15 changes: 15 additions & 0 deletions examples/SeanModule.asn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MyModule DEFINITIONS ::=
BEGIN

MyTypes ::= SEQUENCE {
myObjectId OBJECT IDENTIFIER,
mySeqOf SEQUENCE OF MyInt,
myBitString BIT STRING {
muxToken(0),
modemToken(1)
}
}

MyInt ::= INTEGER (0..65535)

END
Loading