asn1cpp icon indicating copy to clipboard operation
asn1cpp copied to clipboard

How to get/set BIT_STRING_t

Open Octlot opened this issue 4 years ago • 3 comments

BIT_STRING_t define like this: DriveBehavior ::= BIT STRING { goStraightForward(0), laneChangingToLeft(1), laneChangingToRight(2) } (SIZE(14,...))

What can I get/set bitstring by getField or setField?

Octlot avatar Nov 17 '21 08:11 Octlot

Currently it seems like BIT_STRING_t is not implemented. We have support for OCTET_STRING_t. This is the code that enables that:

        struct Setter<OCTET_STRING_t> {
            bool operator()(OCTET_STRING_t * field, const std::string & value) {
                return OCTET_STRING_fromBuf(field, value.data(), value.size()) == 0;
            }
            bool operator()(OCTET_STRING_t * field, const char * value) {
                return operator()(field, std::string(value));
            }
            bool operator()(OCTET_STRING_t * field, const OCTET_STRING_t * value) {
                return OCTET_STRING_fromBuf(field, reinterpret_cast<const char *>(value->buf), value->size) == 0;
            }
        };

It is likely that to support a BIT_STRING_t will require code that is quite similar to this. I can try to look into that when I have some time, or feel free to do so yourself and report your findings here.

If this is the case then adding support should be fairly easy. If not, we'll have to look into it.

Svalorzen avatar Nov 17 '21 09:11 Svalorzen

I looked a bit into it, it might not be super difficult.

The main issue is what you would like to have on the C++ side. Would an std::vector<bool> work, for example?

Svalorzen avatar Nov 17 '21 10:11 Svalorzen

std::vector<bool> unfortunately won't really work as we cannot get access to its underlying storage with data(). I think it'll have to be an std::string, but then when setting you will lose the information of how many bits are supposed to be unused (the bits_unused field in BIT_STRING_t.

Svalorzen avatar Nov 17 '21 10:11 Svalorzen