Skip to content
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

How to use parse_files for filling the values of the keys in the dictionary #29

Closed
ashwin2701 opened this issue Sep 20, 2018 · 12 comments
Closed

Comments

@ashwin2701
Copy link

ashwin2701 commented Sep 20, 2018

My requirement is to create a dictionary based on the asn file and then fill the key's value using an excel sheet, and then later encode/decode .Currently I'm manually creating the desired output and filling its values from the excel sheet, Now for the below schema, Is the Parsed output and desired output both same?if both are same how do we fill values for the keys inside a dictionary? If not how to make the parser output equivalent to desired output?Any recommendations would be highly helpful.

Module-order DEFINITIONS AUTOMATIC TAGS ::=

BEGIN

Order ::= SEQUENCE {

header Order-header

}

Order-header ::= SEQUENCE {

reference NumericString (SIZE (12)),

date NumericString (SIZE (8)) -- MMDDYYYY --

}END

Parser Output

        foo = asn1tools.parse_files('we.asn')

        foo

{'Module-order': {'extensibility-implied': False, 'tags': 'AUTOMATIC', 'imports': {}, 'object-sets': {}, 'values': {}, 'object-classes': {}, 'types': {'Order': {'type': 'SEQUENCE', 'members': [{'type': 'Order-header', 'name': 'header'}]}, 'Order-header': {'type': 'SEQUENCE', 'members': [{'type': 'NumericString', 'name': 'reference', 'size': [12]}, {'type': 'NumericString', 'name': 'date', 'size': [8]}]}}}}

{header:{reference:NumericString (SIZE (12)),date NumericString (SIZE (8)) -- MMDDYYYY --}}

Desired Output

{'header':{'reference': NumericString,'date':NumericString}}

@eerimoq
Copy link
Owner

eerimoq commented Sep 20, 2018

Sorry, but transforming one dictionary to another is out of scope of this project.

@ashwin2701
Copy link
Author

So for encoding or decoding we have to pass some integer or string value to dictionaries which we create right,how it is done

@eerimoq
Copy link
Owner

eerimoq commented Sep 20, 2018

You have to be more specific. It's impossible to understand what you want to achieve.

@ashwin2701
Copy link
Author

ashwin2701 commented Sep 20, 2018

Parse_files function will create a dictionary which will have members ,and type of members may be string or integer etc ,Now with respect to my understanding for encoding or decoding to happen we give the members with value such as 1,2 etc which is integer datatype,So my question was that is there way to give values to the members

@eerimoq
Copy link
Owner

eerimoq commented Sep 20, 2018

@eerimoq
Copy link
Owner

eerimoq commented Sep 21, 2018

I still don't understand what you want to achieve, sorry.

@ashwin2701
Copy link
Author

ashwin2701 commented Sep 21, 2018

How can we assign values to the members of the dictionary which your module is creating.

@ashwin2701
Copy link
Author

Can the value for the members be assigned through the program itself.

@ashwin2701
Copy link
Author

import asn1tools
foo = asn1tools.compile_files('tests/files/foo.asn')
encoded = foo.encode('Question', {'id': 1, 'question': 'Is 1+1=3?'})
encoded
bytearray(b'0\x0e\x02\x01\x01\x16\x09Is 1+1=3?')
foo.decode('Question', encoded)
{'id': 1, 'question': 'Is 1+1=3?'}

Now it looks OK since there are only two members inside Question schema but consider a scenario where i need to assign value for member3 with value 4 which is under schema of schema of schema.Then to encode you need to do something like this

encoded = foo.encode('Random', {'member1': {member2:{member3:4}}})

Is there a way where you give value for member3=4 and it itself creates the dictionary of dictionaries format for encoding based on hierarchy got from asn1tools.parse_files('tests/files/foo.asn')

@eerimoq
Copy link
Owner

eerimoq commented Sep 21, 2018

No, there is no support in asn1tools for using the dictionary created by parse_files() to generate dictionaries with data to encode with foo.encode(). Why do you need that?

@ashwin2701
Copy link
Author

Ok currently I have to handle schema whose members may be again schemas which might extrend upto n levels,Now my task is to create a dictionary of dictionaries for any schema,and value for its members i will fill through an excel sheet, and then later use that dictionary for encoding .I was confused whether I can utilize your asn1tools.parse_files('tests/files/foo.asn') which is returning a dictionary showing the hierarchy of parent dictionary and its child members, and then utilize that hierarchy to fill the values to create the dictionary needed for encoding.

@eerimoq
Copy link
Owner

eerimoq commented Sep 21, 2018

Ok, as that functionality is not supported I suggest closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants