Exemplo n.º 1
0
 public BinaryOverlayListByStartIndexWithRecord(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     BinaryOverlay.SpanFactory <T> getter,
     int itemLength,
     RecordType recordType,
     bool skipHeader)
 {
     this._mem             = mem;
     this._package         = package;
     this._getter          = getter;
     this._itemLength      = itemLength;
     this._recordType      = recordType;
     this._totalItemLength = itemLength + this._package.MetaData.Constants.SubConstants.HeaderLength;
     if (skipHeader)
     {
         _sliceOffset = this._package.MetaData.Constants.SubConstants.HeaderLength;
         _itemOffset  = 0;
     }
     else
     {
         _sliceOffset = 0;
         _itemOffset  = this._package.MetaData.Constants.SubConstants.HeaderLength;
     }
 }
Exemplo n.º 2
0
        public static IReadOnlyList <string> FactoryByCountLength <T>(
            ReadOnlyMemorySlice <byte> mem,
            BinaryOverlayFactoryPackage package,
            byte countLength,
            BinaryOverlay.SpanFactory <string> getter)
        {
            var count = countLength switch
            {
                4 => BinaryPrimitives.ReadUInt32LittleEndian(mem),
                _ => throw new NotImplementedException(),
            };

            int[] locs = new int[count];
            int   loc  = 0;

            for (int i = 0; i < count - 1; i++)
            {
                locs[i] = loc;
                var len = BinaryPrimitives.ReadUInt16LittleEndian(mem.Slice(loc));
                loc += len + 2;
            }
            return(FactoryByArray(
                       mem.Slice(countLength),
                       package,
                       getter,
                       locs));
        }
Exemplo n.º 3
0
        public static IReadOnlyList <T> FactoryByCountLength(
            ReadOnlyMemorySlice <byte> mem,
            BinaryOverlayFactoryPackage package,
            int itemLength,
            byte countLength,
            BinaryOverlay.SpanFactory <T> getter)
        {
            uint count;

            switch (countLength)
            {
            case 4:
                count = BinaryPrimitives.ReadUInt32LittleEndian(mem);
                break;

            default:
                throw new NotImplementedException();
            }
            if (((mem.Length - countLength) / itemLength) < count)
            {
                throw new ArgumentException("Item count and expected size did not match.");
            }
            return(new BinaryOverlayListByStartIndex(
                       mem.Slice(countLength, checked ((int)(count * itemLength))),
                       package,
                       getter,
                       itemLength));
        }
Exemplo n.º 4
0
 public BinaryOverlayListByStartIndex(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     BinaryOverlay.SpanFactory <T> getter,
     int itemLength)
 {
     this._mem        = mem;
     this._package    = package;
     this._getter     = getter;
     this._itemLength = itemLength;
 }
Exemplo n.º 5
0
 public BinaryOverlayListByLocationArray(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     BinaryOverlay.SpanFactory <T> getter,
     int[] locs)
 {
     this._mem       = mem;
     this._getter    = getter;
     this._package   = package;
     this._locations = locs;
 }
Exemplo n.º 6
0
 public static IReadOnlyList <T> FactoryByStartIndex <T>(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     int itemLength,
     BinaryOverlay.SpanFactory <T> getter)
 {
     return(new BinaryOverlayListByStartIndex <T>(
                mem,
                package,
                getter,
                itemLength));
 }
Exemplo n.º 7
0
 public static IReadOnlyList <T> FactoryByArray <T>(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     BinaryOverlay.SpanFactory <T> getter,
     int[] locs)
 {
     return(new BinaryOverlayListByLocationArray <T>(
                mem,
                package,
                getter,
                locs));
 }
Exemplo n.º 8
0
 public BinaryOverlayListByStartIndexWithRecordSet(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     BinaryOverlay.SpanFactory <T> getter,
     int itemLength,
     ICollectionGetter <RecordType> recordTypes)
 {
     this._mem             = mem;
     this._package         = package;
     this._getter          = getter;
     this._itemLength      = itemLength;
     this._recordTypes     = recordTypes;
     this._totalItemLength = itemLength + this._package.MetaData.Constants.SubConstants.HeaderLength;
 }
Exemplo n.º 9
0
        public static IReadOnlyList <T> FactoryByCountPerItem <T>(
            OverlayStream stream,
            BinaryOverlayFactoryPackage package,
            int itemLength,
            int countLength,
            RecordType subrecordType,
            RecordType countType,
            BinaryOverlay.SpanFactory <T> getter,
            bool skipHeader = true)
        {
            var mem           = stream.RemainingMemory;
            var initialHeader = package.MetaData.Constants.SubrecordFrame(mem);
            var recType       = initialHeader.RecordType;

            if (recType == countType)
            {
                var count = countLength switch
                {
                    1 => initialHeader.Content[0],
                    2 => BinaryPrimitives.ReadUInt16LittleEndian(initialHeader.Content),
                    4 => BinaryPrimitives.ReadUInt32LittleEndian(initialHeader.Content),
                    _ => throw new NotImplementedException(),
                };
                var countLen   = initialHeader.TotalLength;
                var contentLen = checked ((int)((itemLength + package.MetaData.Constants.SubConstants.HeaderLength) * count));
                stream.Position += countLen + contentLen;
                return(FactoryByCount(
                           mem.Slice(countLen, contentLen),
                           package: package,
                           itemLength: itemLength,
                           subrecordType: subrecordType,
                           count: count,
                           getter: getter,
                           skipHeader: skipHeader));
            }
            else
            {
                return(FactoryByArray(
                           mem: stream.RemainingMemory,
                           package: package,
                           getter: getter,
                           locs: BinaryOverlay.ParseRecordLocations(
                               stream: stream,
                               constants: package.MetaData.Constants.SubConstants,
                               trigger: subrecordType,
                               skipHeader: true)));
            }
        }
Exemplo n.º 10
0
 public static IReadOnlyList <T> FactoryByCount <T>(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     int itemLength,
     uint count,
     BinaryOverlay.SpanFactory <T> getter)
 {
     if ((mem.Length / itemLength) != count)
     {
         throw new ArgumentException("Item count and expected size did not match.");
     }
     return(new BinaryOverlayListByStartIndex <T>(
                mem,
                package,
                getter,
                itemLength));
 }
Exemplo n.º 11
0
        public static IReadOnlyList <T> FactoryByCount <T>(
            OverlayStream stream,
            BinaryOverlayFactoryPackage package,
            int itemLength,
            int countLength,
            RecordType subrecordType,
            RecordType countType,
            BinaryOverlay.SpanFactory <T> getter)
        {
            var mem           = stream.RemainingMemory;
            var initialHeader = package.MetaData.Constants.SubrecordFrame(mem);
            var recType       = initialHeader.RecordType;

            if (recType == countType)
            {
                var count = countLength switch
                {
                    1 => initialHeader.Content[0],
                    2 => (int)BinaryPrimitives.ReadUInt16LittleEndian(initialHeader.Content),
                    4 => checked ((int)BinaryPrimitives.ReadUInt32LittleEndian(initialHeader.Content)),
                    _ => throw new NotImplementedException(),
                };
                stream.Position += initialHeader.TotalLength;
                if (!stream.TryReadSubrecordFrame(subrecordType, out var contentFrame))
                {
                    if (count == 0)
                    {
                        return(Array.Empty <T>());
                    }
                    throw new ArgumentException($"List with a non zero {initialHeader.RecordType} counter did not follow up with expected type: {subrecordType}");
                }
                return(new BinaryOverlayListByStartIndex <T>(
                           contentFrame.Content,
                           package,
                           getter,
                           itemLength));
            }
            else
            {
                return(FactoryByStartIndex(
                           mem: stream.RemainingMemory,
                           package: package,
                           getter: getter,
                           itemLength: itemLength));
            }
        }
Exemplo n.º 12
0
 public static IReadOnlyList <T> FactoryByCount <T>(
     ReadOnlyMemorySlice <byte> mem,
     BinaryOverlayFactoryPackage package,
     ICollectionGetter <RecordType> subrecordType,
     int itemLength,
     uint count,
     BinaryOverlay.SpanFactory <T> getter)
 {
     if ((mem.Length / (itemLength + package.MetaData.Constants.SubConstants.HeaderLength)) != count)
     {
         throw new ArgumentException("Item count and expected size did not match.");
     }
     return(new BinaryOverlayListByStartIndexWithRecordSet <T>(
                mem,
                package,
                getter,
                itemLength,
                subrecordType));
 }
Exemplo n.º 13
0
        public static IReadOnlyList <T>?FactoryByCountNullIfZero <T>(
            OverlayStream stream,
            BinaryOverlayFactoryPackage package,
            int itemLength,
            int countLength,
            RecordType subrecordType,
            RecordType countType,
            BinaryOverlay.SpanFactory <T> getter)
        {
            var mem           = stream.RemainingMemory;
            var initialHeader = package.MetaData.Constants.SubrecordFrame(mem);
            var recType       = initialHeader.RecordType;

            if (recType == countType)
            {
                var count = countLength switch
                {
                    1 => initialHeader.Content[0],
                    2 => (int)BinaryPrimitives.ReadUInt16LittleEndian(initialHeader.Content),
                    4 => checked ((int)BinaryPrimitives.ReadUInt32LittleEndian(initialHeader.Content)),
                    _ => throw new NotImplementedException(),
                };
                stream.Position += initialHeader.TotalLength;
                if (count == 0)
                {
                    return(null);
                }
                var contentFrame = stream.ReadSubrecordFrame(subrecordType);
                return(new BinaryOverlayListByStartIndex <T>(
                           contentFrame.Content,
                           package,
                           getter,
                           itemLength));
            }
            else
            {
                return(FactoryByStartIndex(
                           mem: stream.RemainingMemory,
                           package: package,
                           getter: getter,
                           itemLength: itemLength));
            }
        }