Hi,
I am converting data from an asn1 stream but my problem is with converting integer values. Asn1 works on a Tag, Length, Value (TLV) notation, so an integer can be stored in a variable length field. When that length is 1, 2 or 4 the conversion to a decimal value is relatively straight forward I am just doing this:
Basically casting it to the appropriately sized variable. However when the variable is not of a standard size eg 3 bytes I am not entirely sure what to do? Should I do a 2's complement conversion to a decimal integer? Thoughts, ideas, suggestions appreciated?Code:ber_tlv_tag_t TagSize; ber_tlv_tag_t TagValue; signed short ssTempInt = 0; signed int siTempInt = 0; switch (TagSize) { case 1: TagValue = *(const uint8_t *)&InputBuffer[CharsUsed]; ThisEvent->DataVolumeGprsUplink = (int) TagValue; break; case 2: ssTempInt = *(const uint16_t *)&InputBuffer[CharsUsed]; ThisEvent->DataVolumeGprsUplink = (int) ssTempInt; break; case 4: siTempInt = *(const uint32_t *)&InputBuffer[CharsUsed]; ThisEvent->DataVolumeGprsUplink = (int) siTempInt; break; default: TRACE(("Tagsize is not easily converted\0")); }
Thanks