Class DataResolver


  • public class DataResolver
    extends java.lang.Object
    Data extraction helper, with support for selected transforms.

    The class follows path segments into an array or structure or other base data instance, possibly concluding with a bit index.

    A static method starts from a given CipTree instance.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      int bit
      Bit index that applies to the subscripted element of data, or, if already a CipBOOL, the bit used to produce that CipBOOL.
      PathSegment bitHost
      The selector that yielded a hosted bit.
      BaseDataType<?> data
      Innermost data instance not including subscripts or any bit index.
      BaseDataType<?> data0
      Outermost data instance.
      BaseDataType<?> data1
      Fully subscripted/bit selected data instance.
      int[] dims
      Dimensions of data extracted for convenience.
      boolean hasDebug  
      boolean hasTrace  
      int[] indices
      Accumulated subscripts that apply to data.
      protected BaseDataType<?>[] indirectobjs
      The indirection values that were extracted from the context at the indirection selectors encountered.
      protected int[] indirects
      The nesting levels at which indirection selectors were encountered.
      int priorBytes
      The number of bytes of bytes between the start of data0 and data.
      java.lang.Long unusedParasiteBits
      When a hosted bit, holds the unused bits of that host.
    • Constructor Summary

      Constructors 
      Constructor Description
      DataResolver​(DataContext ctx, BaseDataType<?> root, java.util.List<PathSegment> path, int nesting)
      Given a data element and a path containing zero or more selector segments, resolve the selectors to locate a specific subelement.
    • Field Detail

      • data0

        public final BaseDataType<?> data0
        Outermost data instance.
      • data

        public BaseDataType<?> data
        Innermost data instance not including subscripts or any bit index.
      • data1

        public final BaseDataType<?> data1
        Fully subscripted/bit selected data instance.
      • dims

        public int[] dims
        Dimensions of data extracted for convenience.
      • indices

        public int[] indices
        Accumulated subscripts that apply to data. These are always zero-based. Member offsets are applied as these are accumulated.
      • bit

        public int bit
        Bit index that applies to the subscripted element of data, or, if already a CipBOOL, the bit used to produce that CipBOOL.
      • bitHost

        public PathSegment bitHost
        The selector that yielded a hosted bit.
      • unusedParasiteBits

        public java.lang.Long unusedParasiteBits
        When a hosted bit, holds the unused bits of that host.
      • priorBytes

        public int priorBytes
        The number of bytes of bytes between the start of data0 and data. Updated whenever traversal follows a structure member.
      • indirects

        protected int[] indirects
        The nesting levels at which indirection selectors were encountered.
      • indirectobjs

        protected BaseDataType<?>[] indirectobjs
        The indirection values that were extracted from the context at the indirection selectors encountered. Always corresponds 1:1 with indirects.
      • hasDebug

        public final boolean hasDebug
      • hasTrace

        public final boolean hasTrace
    • Constructor Detail

      • DataResolver

        public DataResolver​(DataContext ctx,
                            BaseDataType<?> root,
                            java.util.List<PathSegment> path,
                            int nesting)
        Given a data element and a path containing zero or more selector segments, resolve the selectors to locate a specific subelement.
        Parameters:
        ctx - The reference to use for indirect subscripts, if any
        root - The starting data element
        path - The selectors to follow
        nesting - The number of leading segments to skip
    • Method Detail

      • follow

        public static DataResolver follow​(CipTree tree,
                                          java.util.List<PathSegment> path)
        Follows a path into a CipTree hierarchy, and if it stops on a DataWrapper, continues drilling into that item's data.
        Parameters:
        tree -
        path -
        Returns:
      • isStringable

        public static boolean isStringable​(DataDefinitionSeg outer,
                                           DataContext ctx)
        Helper that examines a data definition segment and determines if it is a structure that fits a Logix-style string type (.LEN and .DATA).
        Parameters:
        outer -
        ctx -
        Returns:
      • followTransform

        public static DataDefinitionSeg followTransform​(DataDefinitionSeg outer,
                                                        PathSegment seg,
                                                        DataContext ctx)
        Helper that identifies supported transform symbols and returns the corresponding data type definition segment.
        Parameters:
        outer -
        seg -
        ctx -
        Returns:
      • newSubscript

        public boolean newSubscript()
        Determine if any indirect subscript has changed in the path to the data.
        Returns:
        True if callers need to re-resolve the path.
      • getOffset

        public int getOffset()
        Obtain the resolved element's byte offset within the outermost data object's complete payload. Not valid when variable-length elements are prior to the resolved element, nor when accessing individual bits.
        Returns:
        Byte offset or -1 when invalid.
      • asSubscripted

        public BaseDataType<?> asSubscripted()
        Obtain the data with the resolved indices encapsulated. Needed to properly support assemblies containing elements of arrays or structures.
        Returns:
        A data item that is a view into the final resolved data item. If no indices nor bit number are present, then this will be the same object as returned in .data.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)