Giter VIP home page Giter VIP logo

Comments (3)

kentkost avatar kentkost commented on May 26, 2024 1

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.

kentkost avatar kentkost commented on May 26, 2024 1

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.

chetanpandey1266 avatar chetanpandey1266 commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.