asn1c icon indicating copy to clipboard operation
asn1c copied to clipboard

BIT_STRING example

Open devendranaga opened this issue 4 years ago • 1 comments

Hello,

Anyone have an example of BIT_STRING encoding and decoding with asn1c?

For example using the below definition:

/* Dependencies */ typedef enum TestValue { Test_Value_unavailable = 0, Test_Value_1 = 1, Test_Value_2 = 2, } e_TestValue;

/* TestValue */ typedef BIT_STRING_t TestValue_t;

Thanks,

devendranaga avatar Aug 11 '21 11:08 devendranaga

Probably this original poster does not need an answer any longer. Anyway here a possible solution for future reference and to be able to close the ticket.

The given structure belongs to following ASN.1 specs:

MyModule DEFINITIONS ::= BEGIN

    TestValue ::= BIT STRING {
        unavailable(0),
        value1(1),
        value2(2)
    }

END

Running asn1c with it creates the file Test-Value.h which contains the Test_Value C enum definition.

And an example of this BIT_STRING encoding could be as follows:

<Test-Value>1100</Test-Value>

Where the initial 3 bits are mapped to unavailable, value1 and value2 respectively and the last bit is not used.

mr-j0nes avatar Mar 05 '25 13:03 mr-j0nes

I think that the above answer is sufficient. If not - please re-open.

mouse07410 avatar Sep 21 '25 14:09 mouse07410