-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asn1tools.codecs.EncodeError: enumeration value #10
Comments
Well, the error message is quite clear, one of the strings "labelA" and "labelB" are expected, not a numerical value. Though, it might be handy if the package allows numerical values as well. |
Thanks for your reply. When we are testing in below site it was expecting numerical values so i was trying with numerical values. |
IS it possible to extract the Enumeration Mapping from a compiled .asn file for a specific enumerated type in order to automatically translate the numerical value to the string ones? I've tried to dig into the stub classes but i was unable to extract the mapping. I think it should be stored somewhere in a property of the enumerated type but I don't know where. |
There is no public API to get this information, sorry. I don't recommend anyone to use internal stuff that may be removed at any point without notice. |
Inspecting the classes i've found that the mapping is in the root_index_to_name and root_name_to_index attributes of the type. It should be possible add a index2index mapping acting on these maps also after the compilation (that is without modifying the asn1tools sourcecode) throught an "fixer function"
This should prevent the error in the topic of this thread make the encoder working with namestring or indexes. |
I agree, however i need this feature beacause my source is sending all the enumerated values in a numeric fashion. My solution should prevent me to traverse the object tree and re-encode all the enumerated values. |
mmm... there is another type check:
Anyway, I've found a way to get the mapping, I'm close to a solution :) |
We could possibly add an optional parameter to |
this is a great idea! I'm trying to apply a sort of real-time patching of the encode method in order to obtain that ... the problem is that the Enumerated.encode is called after the String.encode one ... |
@alexroat Try asn1tools version 0.135.0, available on PyPI, and compile as |
Wonderful!
|
PS: just a feature request: Of course: we can open a new thread for this. |
I don't quite understand the benefit of a "hook" function. Isn't it just easier to convert the data before calling encode and after decode returns? |
Yes, but let me explain. I've obtained a result like that using a run-time method overriding Look at this
|
I think you'll have to continue patching asn1tools as you do today, sorry. |
Yes. Finally I've found a way that is clean and effective enough :) It works great making asn1tools tollerant about the input syntax. Thanks for the support Erik, asn1tools is a great piece of software. |
I'm facing below error when im trying to pass to enumerated value.
`
ASN.1 specification:
-- A simple protocol taken from Wikipedia.
Foo DEFINITIONS ::= BEGIN
END`
Input :
question = {'id': 1, 'question': 'What is this problem'}
Error :
asn1tools.codecs.EncodeError: enumeration value '1' not found in ['labelA', 'labelB']
The text was updated successfully, but these errors were encountered: