Skip to content

How to use pushList with a sequence of choice? #4

@carlosrisma

Description

@carlosrisma

Hi,

I'm making use of asn1cpp for a project and so far everything has been working perfectly. Recently, I have encountered an issue when trying to create a sequence of CHOICE that looks like this:

ISO14823Attributes::= SEQUENCE (SIZE(1..8,...)) OF CHOICE{
	dtm DTM, 	-- Date/Time/Period	
	edt	EDT,	-- Exemption status of Date/Time/Period	
	dfl	DFL,	-- Directional Flow of Lane	
	ved	VED, 	-- Vehicle Dimensions
	spe	SPE, 	-- Speed
	roi	ROI,	-- Rate of Incline
	dbv	DBV,	-- Distance Between Vehicles
	ddd	DDD 	-- Destination/Direction/Distance
	}

With this sequence the asn1c generated ISO14823Attributes.h defines the sequence as: A_SEQUENCE_OF(ISO14823Attributes__Member) list; and with the ISO14823Attributes__Member struct defined in the same .h file(I'm attaching the file for better understanding).
The issue is that when trying to create a sequence of the member struct with asn1cpp::makeSeq(ISO14823Attributes__Member) I get an error because it doesn't have an asn type descriptor. On the other hand, a problem arises when trying to manually set the fields
inside the member struct and then trying to do sequenceof::pushList() like this:

auto attr = asn1cpp::makeSeq(ISO14823Attributes);

ISO14823Attributes__Member attr_m;
attr_m.present = ISO14823Attributes__Member_PR_spe;
attr_m.choice.spe = spe_content;

asn1ccp::sequenceOf::pushList(*attr,attr_m);

The error that I get when trying to build says that there is no match for the call to (asn1cpp::Impl::Setter<ISO14823Attributes__Member, void>) (ISO14823Attributes__Member*&, const ISO14823Attributes__Member&).

In an attempt to solve the issue, I added a new macro based on pushList that avoids the use of asn1cpp::setterField() like it is done in asn1cpp::setOf::adderElement() that look like this:

 template <typename T, typename V>
        bool adderChoice(T & field, const V & value) {
            V *ptr = static_cast<V*>(calloc(1,sizeof(V)));

            if(!ptr) {
                return false;
            }

            *ptr=value;

            return ASN_SET_ADD(&field, ptr) == 0;
        } 

With this, I was able to successfully create the sequence but another error comes up when the destructor of the Seq<ISO14823Attributes> object is destroyed and the line def_->op->free_struct(def_, seq_, ASFM_FREE_EVERYTHING); in Seq.hpp, is called. As far as I understand this issue has to do with the fact that avoiding the use of asn1cpp::setterField() also means avoiding the use of the View object that takes care of some memory handling but I don't fully understand how it works.

I would like to ask if there is something I'm missing or if there is any other way to treat this kind of structure "SEQUENCE OF CHOICE". I also let you the .asn containing this structure in case it serves of any help.

Thank you very much in advance for your time and help.
files.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions