How to get result value from inside structure?

0 votes
asked Aug 19, 2018 in Python by hamiltont (360 points)

I have a format like this: 

Data (structure):
  Path Table Size (structure reference to "16bit both-order numbers":
    Big (number)
    Little (number)
  Path Table Locator (script)

In my script, I am trying to get the value of either Big or Little (they are the same). I can locate use getResultByName to isolate "Path Table Size", but I don't know how to get the value from there. I've tried calling getStructure() which gives me the "16bit both-order numbers" structure, and I can access the Big and Little elements from within that, but as far as I can tell there is no way to get a Result from an Element. I've also tried variations of combining the structure names e.g. getResultByName("Path Table Size.Big") - no luck here. 

Is there some method to achieve this?

1 Answer

0 votes
answered Aug 23, 2018 by andreas (3,300 points)
Only the results point to the grammar with its structures and elements, the grammar doesn't know about parsing results.

For each result you can ask for its Value using getValue(). That value can be for example a StringValue or NumberValue -> see Value.getType(). Depending on the type you can call then for example getUnsigned() or getString().

A parsing result for a structure has usually no value unless you specify an expression for it in the grammar. This is useful mainly for the GUI in order to see quicker what's a structure about by displaying the value of one of its elements.