Comments (3)
PDU is usually the the top most object you want to decode.
By setting the -DPDU option then the converter-sample will via. macros set the PDU you want to decode. Otherwise you would have to program it yourself manually.
Look at the quickstart example
You could for example have a grammar like this:
TestModule DEFINITIONS ::= BEGIN
Circle ::= SEQUENCE {
position-x INTEGER,
position-y INTEGER,
radius INTEGER (0..MAX)
}
Rectangle::= SEQUENCE {
length INTEGER,
width INTEGER
}
END
Because this effectively have two PDUs to choose from you could make two different converters from it like so
gcc -DPDU=Circle -I. -o CircleDecoder.exe *.c
and
gcc -DPDU=Rectangle -I. -o RectangleDecoder.exe *.c
In order to better understand the preprocessors in converter-example.
You can try passing -E
to gcc as you compile. This will generate a .i
file that shows the value after preprocessing.
from asn1c.
There are multiple ways to do this. Again read the quickstart example
And there is also the documentation.
It is hard to help when I can't see the code. And i don't know what you want to decode it to.
Long code short.
char buf[1024]; /* Temporary buffer */
asn_dec_rval_t rval; /* Decoder return value */
Circle_t *circle = 0; /* Type to decode. Note this 0! */
FILE *fp; /* Input file handler */
size_t size; /* Number of bytes read */
char *filename="E:\\path\\to\\der\\data.der"; /* Input file name */
/* Open input file as read-only binary */
fp = fopen(filename, "rb");
if(!fp) {
perror(filename);
exit(1);
}
/* Read up to the buffer size */
size = fread(buf, 1, sizeof(buf), fp);
fclose(fp);
if(!size) {
fprintf(stderr, "%s: Empty or broken\n", filename);
exit(1);
}
/* Decode the input buffer as circle type */
rval = ber_decode(0, &asn_DEF_Circle, (void **)&circle, buf, size);
if(rval.code != RC_OK) {
fprintf(stderr, "%s: Broken Circle encoding at byte %ld\n", filename, (long)rval.consumed);
exit(1);
}
/*Encode to whatever you want into a buffer*/
// choose what output should be
enum asn_transfer_syntax osyntax = ATS_BASIC_XER;
asn_TYPE_descriptor_t *pduType = &asn_DEF_Circle;
asn_encode_to_new_buffer_result_t res = asn_encode_to_new_buffer(NULL, osyntax, pdutype, circle);
from asn1c.
Hey I tried this and I am getting the decoder. Now the decoder takes an argument iber
which is what I understand is the ber encoded data. Now I have a ber encoded string which I want to decode, how should I pass it to the decoder? I tried passing it directly but that didn't worked.
from asn1c.
Related Issues (20)
- Is it possible to use ASN1C without dynamic memory allocation? HOT 4
- ASN1C compiler error while compiling HOT 2
- Can't understand the parameters in ber_decoder.h
- fatal_error: asn_application.h: No such file or directory
- Is this library actually working? HOT 3
- sysexits.h error HOT 1
- Extensible integer with a max value in the extension UPER decoding
- definition of struct ProtocolIE_SingleContainer missing HOT 1
- 'Member' cannot be defined in a parameter type
- setenv and unsetenv not working in Windows
- Unable to parse the asn file for mms in wireshark because it references an external structure HOT 2
- v0.9.28 - Leftshift of negative value
- Problem installing HOT 4
- Problem switching between the versions of asn1c in Windows
- Where the "timezone" variable is defined.
- No defination of random() in asn_random_fill.c HOT 2
- Problem compiling: contains no objects
- make check in skeletons fails to build on WSL 22.4
- Syntax error: token "WITH" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asn1c.