예제 #1
0
            public override bool MoveNext()
            {
                if (Index < 0)                 // enumerator стоит перед первой записью
                {
                    MetaInfo = (TMetaInfo)((IMarketDataSerializer)Serializer).CreateMetaInfo(_originalMetaInfo.Date);
                    MetaInfo.CopyFrom(_originalMetaInfo);
                    Index = 0;
                }

                if (Index >= MetaInfo.Count)
                {
                    return(false);
                }

                if (Index == PartSize)
                {
                    PartSize += Reader.ReadInt();
                }

                Current  = Serializer.MoveNext(this);
                Previous = Current;

                if (Index == (PartSize - 1))
                {
                    //Reader.AlignReader();
                    if ((Reader.Offset % 8) != 0)
                    {
                        var shift = ((Reader.Offset / 8) * 8 + 8) - Reader.Offset;
                        Reader.Offset += shift;
                    }
                }

                Index++;

                return(true);
            }
        public static void WritePrice <T>(this BitArrayWriter writer, decimal price, decimal prevPrice, MetaInfo <T> info, SecurityId securityId, bool useLong = false)
            where T : MetaInfo <T>
        {
            if ((price % info.PriceStep) != 0)
            {
                throw new ArgumentException(LocalizedStrings.Str1007Params.Put(info.PriceStep, securityId, price), "info");
            }

            try
            {
                var stepCount = (long)((price - prevPrice) / info.PriceStep);

                // ОЛ может содержать заявки с произвольно большими ценами
                if (useLong)
                {
                    writer.WriteLong(stepCount);
                }
                else
                {
                    writer.WriteInt((int)stepCount);
                }
            }
            catch (OverflowException ex)
            {
                throw new ArgumentException(LocalizedStrings.Str1008Params.Put(price, prevPrice, info.PriceStep, useLong), ex);
            }
        }
        public static decimal ReadPrice <T>(this BitArrayReader reader, decimal prevPrice, MetaInfo <T> info, bool useLong = false)
            where T : MetaInfo <T>
        {
            var count = useLong ? reader.ReadLong() : reader.ReadInt();

            return(prevPrice + count * info.PriceStep);
        }