esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems
https://www.thanassis.space/asn1.html
Other
272 stars 58 forks source link

Load values from ASN.1 Value Notation #208

Closed kliberty closed 3 years ago

kliberty commented 3 years ago

Is it possible to load values from a file that are written in the ASN.1 value notation? I'm working on an input deck for an application and am a fan of the ASN.1 syntax + validation.

With the schema

Prompt ::=  SEQUENCE {
    title       VisibleString    SIZE(1..100),
    message     SEQUENCE OF VisibleString    SIZE(1..7)
}

load a value from a text file into a native data structure

value Prompt ::= 
{
  title "My title",
  message 
  {
    "line 1",
    "line 2"
  }
}
maxime-esa commented 3 years ago

Yes you can have the values in a separate file and have it compiled with the grammar.

In practice:

END


* Then compile the two files together:

asn1.exe -Ada mygrammar.asn myvalues.asn

or if you target C/C++:

asn1.exe -c mygrammar.asn myvalues.asn


And you will get the source code:

const Prompt value = { .title = "Hello", .message = { .nCount = 2, .arr = { "line 1", "line 2"
} } };

kliberty commented 3 years ago

Thank you, I didn't actually know you could do that (still learning ASN.1). My original meaning was in a dynamic sense, so that users could provide input to an already built application.

maxime-esa commented 3 years ago

Ah, this is different, this is what is called GSER (Generic String Encoding Rules), a standard textual encoding which we do not have support for at the moment (in the sense that we do not generate parsers and encoders for it in the target language).