pycrate icon indicating copy to clipboard operation
pycrate copied to clipboard

Accessing ASN1 choice values

Open matan1008 opened this issue 1 year ago • 3 comments

Dear developers. I am trying to access values from a choice in ASN1 and in my humble opinion there might be a bug there, for example:

from pycrate_asn1dir.RRCLTE import EUTRA_RRC_Definitions
a = EUTRA_RRC_Definitions.UL_DCCH_Message
a.set_val({'message': ('messageClassExtension', ('c2', ('ueAssistanceInformation-r11', {'criticalExtensions': ('c1', ('ueAssistanceInformation-r11', {}))})))})
print(a.get_at(['message', 'messageClassExtension', 'c2']).get_val())

I might misunderstood the API, but I would expect something to be printed and the get_val to return a non None value - but it returns None.

I would really appreciate your help, thanks!

matan1008 avatar Apr 12 '24 16:04 matan1008

set_val(), set_val_at(), get_val() and get_val_at() are the methods to work on the values. Here, get_at() returns the sub-object, which has however no value, as an object's value always lives at its root, not in sub-objects.

mitshell avatar Apr 13 '24 13:04 mitshell

So assuming I want to check which of the choices exists in the object, the only two way are to catch the exception get_val_at() raises each time it is given a path or to implement a hierarchy-to-list function?

matan1008 avatar Apr 13 '24 14:04 matan1008

You can select the parent value, and check which choice is taken as the 1st component of the value.

mitshell avatar Apr 19 '24 20:04 mitshell