Пример #1
0
        /// <summary>
        /// Gets field ID if possible.
        /// </summary>
        /// <param name="fieldName">Field name.</param>
        /// <param name="fieldType">Field type.</param>
        /// <param name="pathIdx">Path index, changes during jumps.</param>
        /// <param name="actionIdx">Action index.</param>
        /// <returns>Field ID or zero in case there are no matching path.</returns>
        public int GetFieldId(string fieldName, byte fieldType, ref int pathIdx, int actionIdx)
        {
            Debug.Assert(fieldName != null);
            Debug.Assert(pathIdx <= _paths.Length);

            // Get path.
            BinaryStructureEntry[] path = _paths[pathIdx];

            if (actionIdx < path.Length)
            {
                // Get entry matching the action index.
                BinaryStructureEntry entry = path[actionIdx];

                if (entry.IsExpected(fieldName, fieldType))
                {
                    // Entry matches our expectations, return.
                    return(entry.Id);
                }

                if (entry.IsJumpTable)
                {
                    // Entry is a pointer to a jump table.
                    Debug.Assert(entry.Id < _jumps.Length);

                    BinaryStructureJumpTable jmpTbl = _jumps[entry.Id];

                    if (jmpTbl == null)
                    {
                        return(0);
                    }

                    int pathIdx0 = jmpTbl.GetPathIndex(fieldName);

                    if (pathIdx0 < 0)
                    {
                        return(0);
                    }

                    Debug.Assert(pathIdx0 < _paths.Length);

                    entry = _paths[pathIdx0][actionIdx];

                    entry.ValidateType(fieldType);

                    pathIdx = pathIdx0;

                    return(entry.Id);
                }
            }

            // Failed to find anything because this is a new field.
            return(0);
        }