public List <ScopeDescriptor> CreateScopeDescriptors(long minPosition, long maxPosition)
        {
            var scopeDescriptors = new List <ScopeDescriptor>();
            var fieldDescriptors = new List <FieldDescriptor>();

            FieldDescriptor previousFieldDescriptor = null;
            long            previousPosition        = minPosition;
            int             previousByteSize        = 0;

            foreach (var kvp in mPositionMap.OrderBy(x => x.Key).Where(
                         x => x.Key >= minPosition && x.Key < maxPosition))
            {
                long position = kvp.Key;
                int  byteSize = kvp.Value;

                var valueType =
                    byteSize == 2 ? ValueType.Int16 :
                    byteSize == 4 ? ValueType.Int32 :
                    byteSize == 8 ? ValueType.Int64 :
                    throw new InvalidDataException("Expected value of Int16, Int32 or Int64 type.");

                if (previousFieldDescriptor == null || previousFieldDescriptor.ValueType != valueType ||
                    previousPosition + previousByteSize != position)
                {
                    fieldDescriptors.Add(previousFieldDescriptor = new FieldDescriptor
                    {
                        Position    = position - minPosition,
                        RepeatCount = 1,
                        ValueType   = valueType
                    });
                }

                else
                {
                    previousFieldDescriptor.RepeatCount++;
                }

                previousPosition = position;
                previousByteSize = byteSize;
            }

            // TODO: Optimize
            var scopeDescriptor = new ScopeDescriptor {
                Position = fieldDescriptors[0].Position, RepeatCount = 1
            };

            scopeDescriptor.FieldDescriptors.AddRange(fieldDescriptors);
            scopeDescriptors.Add(scopeDescriptor);

            return(scopeDescriptors);
        }
        public List <ScopeDescriptor> CreateScopeDescriptors(long dataSize)
        {
            var scopeDescriptors = new List <ScopeDescriptor>();
            var fieldDescriptors = new List <FieldDescriptor>();

            for (long offset = 0; offset < dataSize;)
            {
                int type = GetBitArrayValue(offset);

                if (type == 3)
                {
                    offset++;
                    continue;
                }

                var fieldDescriptor = new FieldDescriptor
                {
                    Position    = offset,
                    ValueType   = ( ValueType )type,
                    RepeatCount = 1
                };

                int byteSize = 2 << type;

                for ( ; offset < dataSize;)
                {
                    offset += byteSize;

                    if (GetBitArrayValue(offset) != type)
                    {
                        break;
                    }

                    fieldDescriptor.RepeatCount++;
                }

                fieldDescriptors.Add(fieldDescriptor);
            }

            // TODO: Optimize
            var scopeDescriptor = new ScopeDescriptor {
                Position = fieldDescriptors[0].Position, RepeatCount = 1
            };

            scopeDescriptor.FieldDescriptors.AddRange(fieldDescriptors);
            scopeDescriptors.Add(scopeDescriptor);

            return(scopeDescriptors);
        }