pycrate-org / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats, especially telecom ones. Provides an ASN.1 compiler and a CSN.1 runtime.
https://github.com/pycrate-org/pycrate
GNU Lesser General Public License v2.1
32 stars 8 forks source link

Accessing ASN1 choice values #5

Closed matan1008 closed 1 month ago

matan1008 commented 5 months ago

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!

mitshell commented 5 months ago

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.

matan1008 commented 5 months ago

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?

mitshell commented 4 months ago

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