示例#1
0
        public override IDataFormat CreateDataFormat(IDataModel data, int index)
        {
            var offsets        = ConvertByteOffsetToArrayOffset(index);
            var currentSegment = ElementContent[offsets.SegmentIndex];

            if (currentSegment.Type == ElementContentType.PCS)
            {
                if (currentCachedStartIndex != offsets.SegmentStart || currentCachedIndex > offsets.SegmentOffset)
                {
                    currentCachedStartIndex = offsets.SegmentStart;
                    currentCachedIndex      = offsets.SegmentOffset;
                    cachedCurrentString     = PCSString.Convert(data, offsets.SegmentStart, currentSegment.Length);
                }

                return(PCSRun.CreatePCSFormat(data, offsets.SegmentStart, index, cachedCurrentString));
            }

            var position = index - offsets.SegmentStart;

            if (currentSegment.Type == ElementContentType.Integer)
            {
                if (currentSegment is ArrayRunEnumSegment enumSegment)
                {
                    var value = enumSegment.ToText(data, index);
                    return(new IntegerEnum(offsets.SegmentStart, position, value, currentSegment.Length));
                }
                else
                {
                    var value = ArrayRunElementSegment.ToInteger(data, offsets.SegmentStart, currentSegment.Length);
                    return(new Integer(offsets.SegmentStart, position, value, currentSegment.Length));
                }
            }

            if (currentSegment.Type == ElementContentType.Pointer)
            {
                var destination     = data.ReadPointer(offsets.SegmentStart);
                var destinationName = data.GetAnchorFromAddress(offsets.SegmentStart, destination);
                return(new Pointer(offsets.SegmentStart, position, destination, destinationName));
            }

            if (currentSegment.Type == ElementContentType.BitArray)
            {
                return(new BitArray(offsets.SegmentStart, position, currentSegment.Length));
            }

            throw new NotImplementedException();
        }
        public override IDataFormat CreateDataFormat(IDataModel data, int index)
        {
            var naturalLength = ElementCount * ElementLength;
            var naturalStop   = Start + naturalLength;

            if (index >= naturalStop)
            {
                return(new EndStream(naturalStop, index - naturalStop, Length - naturalLength));
            }

            var offsets        = this.ConvertByteOffsetToArrayOffset(index);
            var currentSegment = ElementContent[offsets.SegmentIndex];

            if (currentSegment.Type == ElementContentType.PCS)
            {
                if (currentCachedStartIndex != offsets.SegmentStart || currentCachedIndex > offsets.SegmentOffset)
                {
                    currentCachedStartIndex = offsets.SegmentStart;
                    currentCachedIndex      = offsets.SegmentOffset;
                    cachedCurrentString     = data.TextConverter.Convert(data, offsets.SegmentStart, currentSegment.Length);
                }

                var pcsFormat = PCSRun.CreatePCSFormat(data, offsets.SegmentStart, index, cachedCurrentString);
                if (offsets.SegmentIndex == 0)
                {
                    return(new StreamEndDecorator(pcsFormat));
                }
                return(pcsFormat);
            }

            var format = this.CreateSegmentDataFormat(data, index);

            if (offsets.SegmentIndex == 0)
            {
                return(new StreamEndDecorator(format));
            }
            return(format);
        }