public void Deserialize(IPrimitiveReader reader, int version)
        {
            //MultiItemResult
            if (reader.ReadByte() != 0)
            {
                multiItemResult = new MultiItemResult();
                multiItemResult.Deserialize(reader);
            }

            //Metadata
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                metadata = reader.ReadBytes(len);
            }

            //IndexSize
            indexSize = reader.ReadInt32();

            //IndexExists
            indexExists = reader.ReadBoolean();

            //ExceptionInfo
            exceptionInfo = reader.ReadString();

            //VirtualCount
            if (version >= 2)
            {
                virtualCount = reader.ReadInt32();
            }
        }
Example #2
0
 /// <summary>
 ///     <para>Deserialize the class data from a stream.</para>
 /// </summary>
 /// <param name="reader">
 ///     <para>The <see cref="IPrimitiveReader"/> that extracts used to extra data from a stream.</para>
 /// </param>
 /// <param name="version">
 ///     <para>The value of <see cref="CurrentVersion"/> that was written to the stream when it was originally serialized to a stream; the version of the <paramref name="reader"/> data.</para>
 /// </param>
 public void Deserialize(IPrimitiveReader reader, int version)
 {
     if (version == 1)
     {
         if (reader.ReadBoolean())
         {
             var keySpace          = DataBuffer.DeserializeValue(reader);
             var descr             = LocalCache.Policy.GetDescription(keySpace);
             var dependencyVersion = reader.ReadInt32();
             CustomDependency = (IObjectDependency)descr.Creator();
             CustomDependency.Deserialize(reader, dependencyVersion);
             Type            = new DependencyType();
             Reference       = null;
             LastUpdatedDate = new DateTime();
         }
         else
         {
             CustomDependency = null;
             Type             = (DependencyType)reader.ReadInt32();
             Reference        = reader.Read <ObjectReference>(false);
             LastUpdatedDate  = reader.ReadDateTime();
         }
     }
     else
     {
         reader.Response = SerializationResponse.Unhandled;
     }
 }
        /// <summary>
        /// Deserialize the class data from a stream.
        /// </summary>
        /// <param name="reader">The <see cref="T:MySpace.Common.IO.IPrimitiveReader"/> that extracts used to extra data from a stream.</param>
        /// <param name="version">The value of <see cref="P:MySpace.Common.IVersionSerializable.CurrentVersion"/> that was written to the stream when it was originally serialized to a stream;
        /// the version of the <paramref name="reader"/> data.</param>
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //FullDataIdType
                FullDataIdType = (FullDataIdType)reader.ReadByte();

                //TagName
                TagName = reader.ReadString();

                if (version >= 2)
                {
                    //Offset
                    reader.ReadInt32();

                    //Count
                    reader.ReadInt32();

                    //DataType
                    DataType = (DataType)reader.ReadByte();

                    //FullDataIdFieldList
                    if (reader.ReadBoolean())
                    {
                        FullDataIdFieldList = new FullDataIdFieldList();
                        Serializer.Deserialize(reader.BaseStream, FullDataIdFieldList);
                    }

                    //FullDataIdPartFormat
                    FullDataIdPartFormat = (FullDataIdPartFormat)reader.ReadByte();
                }
            }
        }
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //IndexExists
            IndexExists = reader.ReadBoolean();

            //DistinctValueCountPairList
            int listCount = reader.ReadInt32();

            DistinctValueCountMapping = new Dictionary <byte[], int>(listCount, new ByteArrayEqualityComparer());
            if (listCount > 0)
            {
                for (int i = 0; i < listCount; i++)
                {
                    //Value
                    ushort len = reader.ReadUInt16();
                    if (len > 0)
                    {
                        DistinctValueCountMapping.Add(reader.ReadBytes(len), reader.ReadInt32());
                    }
                }
            }

            //ExceptionInfo
            ExceptionInfo = reader.ReadString();
        }
Example #5
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //IndexDataItem List
            ushort count = reader.ReadUInt16();

            if (count > 0)
            {
                IndexDataItem indexDataItem;
                for (ushort i = 0; i < count; i++)
                {
                    if (reader.ReadBoolean())
                    {
                        indexDataItem = new IndexDataItem();
                        Serializer.Deserialize(reader.BaseStream, indexDataItem);
                        Add(indexDataItem);
                    }
                }

                //IndexId
                ushort len = reader.ReadUInt16();
                if (len > 0)
                {
                    IndexId = reader.ReadBytes(len);
                }

                //IndexSize
                IndexSize = reader.ReadInt32();

                //IndexExists
                IndexExists = reader.ReadBoolean();

                //IndexCap
                IndexCap = reader.ReadInt32();
            }
        }
 public override void Deserialize(IPrimitiveReader reader)
 {
     IsEmpty   = reader.ReadBoolean();
     Code      = reader.ReadString();
     TitaAppId = reader.ReadInt32();
     TenantId  = reader.ReadInt32();
     UserId    = reader.ReadInt32();
     State     = (QrCodeLoginState)reader.ReadInt16();
 }
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //IndexExists
            IndexExists = reader.ReadBoolean();

            //IndexSize
            IndexSize = reader.ReadInt32();

            //Metadata
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                Metadata = reader.ReadBytes(len);
            }

            //ResultItemList
            int listCount = reader.ReadInt32();

            ResultItemList = new List <ResultItem>(listCount);
            if (listCount > 0)
            {
                ResultItem resultItem;
                for (int i = 0; i < listCount; i++)
                {
                    resultItem = new ResultItem();
                    resultItem.Deserialize(reader);
                    ResultItemList.Add(resultItem);
                }
            }

            //ExceptionInfo
            ExceptionInfo = reader.ReadString();

            //VirtualCount
            if (version >= 2)
            {
                VirtualCount = reader.ReadInt32();
            }

            //IndexCap
            if (version >= 3)
            {
                IndexCap = reader.ReadInt32();
            }

            if (version >= 4)
            {
                //MetadataPropertyCollection
                if (reader.ReadBoolean())
                {
                    MetadataPropertyCollection = new MetadataPropertyCollection();
                    Serializer.Deserialize(reader.BaseStream, MetadataPropertyCollection);
                }
            }
        }
Example #8
0
        public void Deserialize(IPrimitiveReader reader)
        {
            this.pageSize         = reader.ReadInt32();
            this.minValidDateTime = new DateTime(reader.ReadInt64());

            #region cacheTypeCaps
            int count = reader.ReadInt32();
            if (count > 0)
            {
                this.cacheTypeCaps = new Dictionary <int, int>(count);
                for (int i = 0; i < count; i++)
                {
                    this.cacheTypeCaps[reader.ReadInt32()] = reader.ReadInt32();
                }
            }
            #endregion

            #region queryList
            count = reader.ReadInt32();
            if (count > 0)
            {
                this.queryList = new List <Pair <List <byte[]>, List <int> > >(count);
                List <byte[]> IndexIdList   = null;
                List <int>    CacheTypeList = null;

                // IndexId Length in bytes
                int IndexIdLen = reader.ReadInt32();
                int IndexIdListLen;
                int CacheTypeListLen;
                for (int j = 0; j < count; j++)
                {
                    #region  IndexIdList
                    IndexIdListLen = reader.ReadInt32();
                    if (IndexIdListLen > 0)
                    {
                        IndexIdList = new List <byte[]>(IndexIdListLen);
                        for (int k = 0; k < IndexIdListLen; k++)
                        {
                            IndexIdList.Add(reader.ReadBytes(IndexIdLen));
                        }
                    }
                    #endregion

                    #region CacheTypeList
                    CacheTypeListLen = reader.ReadInt32();
                    if (CacheTypeListLen > 0)
                    {
                        CacheTypeList = new List <int>(CacheTypeListLen);
                        for (int l = 0; l < CacheTypeListLen; l++)
                        {
                            CacheTypeList.Add(reader.ReadInt32());
                        }
                    }
                    #endregion

                    this.queryList.Add(new Pair <List <byte[]>, List <int> >(IndexIdList, CacheTypeList));
                }
            }
            #endregion
        }
 public void Deserialize(IPrimitiveReader reader, int version)
 {
     if (version == CurrentVersion)
     {
         MessageType   = (MessageType)reader.ReadInt32();
         PayloadLength = reader.ReadInt32();
         int bytesLength = reader.ReadInt32();
         if (bytesLength > -1)
         {
             byte[] bytes = reader.ReadBytes(bytesLength);
             MessageStream = new MemoryStream(bytes);
         }
     }
 }
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //MultiItemResult
            if (reader.ReadByte() != 0)
            {
                MultiItemResult = new MultiItemResult();
                MultiItemResult.Deserialize(reader);
            }

            //Metadata
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                Metadata = reader.ReadBytes(len);
            }

            //IndexSize
            IndexSize = reader.ReadInt32();

            //IndexExists
            IndexExists = reader.ReadBoolean();

            //ExceptionInfo
            ExceptionInfo = reader.ReadString();

            //VirtualCount
            if (version >= 2)
            {
                VirtualCount = reader.ReadInt32();
            }

            //IndexCap
            if (version >= 3)
            {
                IndexCap = reader.ReadInt32();
            }

            if (version >= 4)
            {
                //MetadataPropertyCollection
                if (reader.ReadBoolean())
                {
                    MetadataPropertyCollection = new MetadataPropertyCollection();
                    Serializer.Deserialize(reader.BaseStream, MetadataPropertyCollection);
                }
            }
        }
Example #11
0
        internal static BarfObjectHeader ReadFrom(IPrimitiveReader reader)
        {
            var value = reader.ReadVarInt32();

            if (value == -1)
            {
                return(NullBarfObjectHeader.Instance);
            }

            if (value < 0)
            {
                reader.RaiseInvalidDataException();
            }
            var result = new BarfObjectHeader {
                Version = value
            };

            value = reader.ReadVarInt32();
            if (value < 0)
            {
                reader.RaiseInvalidDataException();
            }
            result.MinVersion = value;

            value = reader.ReadInt32();
            if (value < 0)
            {
                reader.RaiseInvalidDataException();
            }
            result.Length = value;

            result.StartPosition = reader.BaseStream.Position;

            return(result);
        }
Example #12
0
        /// <summary>
        /// Deserialize the class data from a stream.
        /// </summary>
        /// <param name="reader">The <see cref="T:MySpace.Common.IO.IPrimitiveReader"/> that extracts used to extra data from a stream.</param>
        /// <param name="version">The value of <see cref="P:MySpace.Common.IVersionSerializable.CurrentVersion"/> that was written to the stream when it was originally serialized to a stream;
        /// the version of the <paramref name="reader"/> data.</param>
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //FieldValue
                ushort len = reader.ReadUInt16();
                if (len > 0)
                {
                    FieldValue = reader.ReadBytes(len);
                }
                else
                {
                    new LogWrapper().Error("FieldValue in FilterCaps cannot be null or zero length byte array");
                    throw new Exception("FieldValue in FilterCaps cannot be null or zero length byte array");
                }

                //UseParentFilter
                UseParentFilter = reader.ReadBoolean();

                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    Filter = FilterFactory.CreateFilter(reader, (FilterType)b);
                }

                //Cap
                Cap = reader.ReadInt32();
            }
        }
Example #13
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType)b;
                    filter = FilterFactory.CreateFilter(reader, filterType);
                }

                if (version >= 2)
                {
                    //Count
                    Count = reader.ReadInt32();

                    //IndexCondition
                    if (reader.ReadBoolean())
                    {
                        IndexCondition = new IndexCondition();
                        Serializer.Deserialize(reader.BaseStream, IndexCondition);
                    }
                }
            }
        }
        /// <summary>
        /// Deserializes the internal item.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="inDeserializationContext">The in deserialization context.</param>
        /// <param name="reader">The reader.</param>
        /// <returns>InternalItem</returns>
        private static InternalItem DeserializeInternalItem(byte[] itemId, InDeserializationContext inDeserializationContext, IPrimitiveReader reader)
        {
            byte kvpListCount = reader.ReadByte();

            List <KeyValuePair <int, byte[]> > kvpList = null;

            if (kvpListCount > 0)
            {
                kvpList = new List <KeyValuePair <int, byte[]> >(kvpListCount);
                for (byte j = 0; j < kvpListCount; j++)
                {
                    int    tagHashCode = reader.ReadInt32();
                    ushort tagValueLen = reader.ReadUInt16();
                    byte[] tagValue    = null;
                    if (tagValueLen > 0)
                    {
                        tagValue = reader.ReadBytes(tagValueLen);
                        if (inDeserializationContext.StringHashCodeDictionary != null &&
                            inDeserializationContext.StringHashCodeDictionary.Count > 0 &&
                            inDeserializationContext.StringHashCodeDictionary.ContainsKey(tagHashCode))
                        {
                            tagValue =
                                inDeserializationContext.StringHashCollection.GetStringByteArray(
                                    inDeserializationContext.TypeId, tagValue);
                        }
                    }
                    kvpList.Add(new KeyValuePair <int, byte[]>(tagHashCode, tagValue));
                }
            }
            return(new InternalItem {
                ItemId = itemId, TagList = kvpList
            });
        }
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //IndexId
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                indexId = reader.ReadBytes(len);
            }

            //Offset
            offset = reader.ReadInt32();

            //ItemNum
            itemNum = reader.ReadInt32();

            //TargetIndexName
            targetIndexName = reader.ReadString();

            //Read a byte to account for deprecated CriterionList
            reader.ReadByte();

            //ExcludeData
            excludeData = reader.ReadBoolean();

            //GetMetadata
            getMetadata = reader.ReadBoolean();

            if (version >= 2)
            {
                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType)b;
                    filter = FilterFactory.CreateFilter(reader, filterType);
                }
            }

            if (version >= 3)
            {
                //FullDataIdInfo
                fullDataIdInfo = new FullDataIdInfo();
                Serializer.Deserialize(reader.BaseStream, fullDataIdInfo);
            }
        }
        /// <summary>
        /// Deserializes the internal item.
        /// </summary>
        /// <param name="internalItem">The internal item</param>
        /// <param name="inDeserializationContext">The in deserialization context.</param>
        /// <param name="outDeserializationContext">The out deserialization context.</param>
        /// <param name="reader">The reader.</param>
        private static void DeserializeTags(InternalItem internalItem,
                                            InDeserializationContext inDeserializationContext,
                                            OutDeserializationContext outDeserializationContext,
                                            IPrimitiveReader reader)
        {
            byte kvpListCount = reader.ReadByte();

            if (kvpListCount > 0)
            {
                internalItem.TagList = new List <KeyValuePair <int, byte[]> >(kvpListCount);
                for (byte j = 0; j < kvpListCount; j++)
                {
                    int    tagHashCode = reader.ReadInt32();
                    ushort tagValueLen = reader.ReadUInt16();
                    byte[] tagValue    = null;
                    if (tagValueLen > 0)
                    {
                        tagValue = reader.ReadBytes(tagValueLen);
                        if (inDeserializationContext.StringHashCodeDictionary != null &&
                            inDeserializationContext.StringHashCodeDictionary.Count > 0 &&
                            inDeserializationContext.StringHashCodeDictionary.ContainsKey(tagHashCode))
                        {
                            tagValue = inDeserializationContext.StringHashCollection.GetStringByteArray(inDeserializationContext.TypeId, tagValue);
                        }
                    }
                    internalItem.TagList.Add(new KeyValuePair <int, byte[]>(tagHashCode, tagValue));
                }
            }

            //Get Distinct Values
            if (!String.IsNullOrEmpty(inDeserializationContext.GetDistinctValuesFieldName))
            {
                byte[] distinctValue;
                if (String.Equals(inDeserializationContext.GetDistinctValuesFieldName, "ItemId", StringComparison.OrdinalIgnoreCase))
                {
                    distinctValue = internalItem.ItemId;
                }
                else
                {
                    internalItem.TryGetTagValue(inDeserializationContext.GetDistinctValuesFieldName, out distinctValue);
                }

                if (distinctValue != null)
                {
                    if (outDeserializationContext.DistinctValueCountMapping.ContainsKey(distinctValue))
                    {
                        outDeserializationContext.DistinctValueCountMapping[distinctValue] += 1;
                    }
                    else
                    {
                        outDeserializationContext.DistinctValueCountMapping.Add(distinctValue, 1);
                    }
                }
            }
        }
Example #17
0
        /// <summary>
        /// Deserializes a <see cref="RelayPayload"/> from an <see cref="IPrimitiveReader"/>.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="version">The version of the <paramref name="reader"/> data.</param>
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            this.TypeId           = reader.ReadInt16();
            this.Id               = reader.ReadInt32();
            this.LastUpdatedTicks = reader.ReadInt64();
            this.Compressed       = reader.ReadBoolean();
            this.ttl              = reader.ReadInt32();
            this.expirationTicks  = reader.ReadInt64();
            int byteLength = reader.ReadInt32();

            if (byteLength > 0)
            {
                this.ByteArray = reader.ReadBytes(byteLength);
            }
            if (version > 1)
            {
                int keyLength = reader.ReadInt32();
                this.ExtendedId = reader.ReadBytes(keyLength);
            }
        }
Example #18
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //Metadata
            ushort len = reader.ReadUInt16();
            if (len > 0)
            {
                metadata = reader.ReadBytes(len);
            }

            //VirtualCount
            virtualCount = reader.ReadInt32();
        }
Example #19
0
        /// <summary>
        /// Returns a data buffer instance deserialized from a stream using the
        /// format version number read from the stream.
        /// </summary>
        /// <param name="reader">
        ///     <para>The <see cref="IPrimitiveReader"/> that extracts used to extra data from a stream.</para>
        /// </param>
        /// <returns>The <see cref="StorageKey"/> deserialized from
        /// <paramref name="reader"/>.</returns>
        /// <exception cref="ApplicationException">
        /// <para>The deserialization failed.</para>
        /// </exception>
        public static StorageKey DeserializeValue(IPrimitiveReader reader)
        {
            var ret     = new StorageKey();
            var version = reader.ReadInt32();

            ret.Deserialize(reader, version);
            if (reader.Response != SerializationResponse.Success)
            {
                throw new ApplicationException("Could not deserialize");
            }
            return(ret);
        }
Example #20
0
 /// <summary>
 ///     <para>Deserialize the class data from a stream.</para>
 /// </summary>
 /// <param name="reader">
 ///     <para>The <see cref="IPrimitiveReader"/> that extracts used to extra data from a stream.</para>
 /// </param>
 /// <param name="version">
 ///     <para>The value of <see cref="CurrentVersion"/> that was written to the stream when it was originally serialized to a stream; the version of the <paramref name="reader"/> data.</para>
 /// </param>
 public void Deserialize(IPrimitiveReader reader, int version)
 {
     if (version == 1)
     {
         Key         = DataBuffer.DeserializeValue(reader);
         PartitionId = reader.ReadInt32();
     }
     else
     {
         reader.Response = SerializationResponse.Unhandled;
     }
 }
        public void Deserialize(IPrimitiveReader reader)
        {
            this.pageSize         = reader.ReadInt32();
            this.pageNum          = reader.ReadInt32();
            this.minValidDateTime = new DateTime(reader.ReadInt64());
            int count = reader.ReadInt32();

            indexIdList = new List <byte[]>(count);
            if (count > 0)
            {
                int keyLen = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    indexIdList.Add(reader.ReadBytes(keyLen));
                }
            }
            count         = reader.ReadInt32();
            cacheTypeList = new List <int>(count);
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    cacheTypeList.Add(reader.ReadInt32());
                }
            }
        }
Example #22
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //IndexId
                ushort len = reader.ReadUInt16();
                if (len > 0)
                {
                    IndexId = reader.ReadBytes(len);
                }

                //Count
                Count = reader.ReadInt32();

                //TargetIndexName
                TargetIndexName = reader.ReadString();

                //ExcludeData
                ExcludeData = reader.ReadBoolean();

                //GetMetadata
                GetMetadata = reader.ReadBoolean();

                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType)b;
                    Filter = FilterFactory.CreateFilter(reader, filterType);
                }

                //FullDataIdInfo
                if (reader.ReadBoolean())
                {
                    FullDataIdInfo = new FullDataIdInfo();
                    Serializer.Deserialize(reader.BaseStream, FullDataIdInfo);
                }

                //IndexCondition
                if (reader.ReadBoolean())
                {
                    IndexCondition = new IndexCondition();
                    Serializer.Deserialize(reader.BaseStream, IndexCondition);
                }

                if (version >= 2)
                {
                    //DomainSpecificProcessingType
                    DomainSpecificProcessingType = (DomainSpecificProcessingType)reader.ReadByte();
                }
            }
        }
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //Metadata
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                metadata = reader.ReadBytes(len);
            }

            //VirtualCount
            virtualCount = reader.ReadInt32();
        }
Example #24
0
        private static List <IndexDataItem> DeserializeIndexDataItemList(IPrimitiveReader reader)
        {
            int listCount = reader.ReadInt32();
            List <IndexDataItem> indexDataItemList = new List <IndexDataItem>(listCount);
            IndexDataItem        indexDataItem;

            for (int i = 0; i < listCount; i++)
            {
                indexDataItem = new IndexDataItem();
                indexDataItem.Deserialize(reader);
                indexDataItemList.Add(indexDataItem);
            }
            return(indexDataItemList);
        }
Example #25
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //MaxItems
                maxItems = reader.ReadInt32();

                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType)b;
                    filter = FilterFactory.CreateFilter(reader, filterType);
                }
            }
        }
        /// <summary>
        /// Reads the serialized header
        /// </summary>
        /// <param name="reader"></param>
        public void Read(IPrimitiveReader reader)
        {
            this.headerPosition = reader.BaseStream.Position;
            this.headerVersion  = reader.ReadByte();
            this.headerLength   = reader.ReadInt16();
            this.flags          = (TypeSerializationHeaderFlags)reader.ReadByte();
            this.dataVersion    = reader.ReadByte();
            this.dataMinVersion = reader.ReadByte();
            this.dataLength     = reader.ReadInt32();
            this.dataPosition   = this.headerPosition + this.headerLength;

            if (this.headerVersion > CurrentHeaderVersion)
            {
                throw new ApplicationException("This object was serialized with a newer version of the serialization framework");
            }
            if ((this.flags & ~TypeSerializationHeaderFlags.KnownFlags) != 0)
            {
                throw new ApplicationException("This object was serialized with features that are not supported in this version of the serialization framework");
            }

            reader.BaseStream.Seek(this.dataPosition, System.IO.SeekOrigin.Begin);
        }
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //IndexId
                ushort len = reader.ReadUInt16();
                if (len > 0)
                {
                    indexId = reader.ReadBytes(len);
                }

                //Count
                count = reader.ReadInt32();

                //TargetIndexName
                targetIndexName = reader.ReadString();

                //ExcludeData
                excludeData = reader.ReadBoolean();

                //GetMetadata
                getMetadata = reader.ReadBoolean();

                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType)b;
                    filter = FilterFactory.CreateFilter(reader, filterType);
                }

                if (version >= 2)
                {
                    //FullDataIdInfo
                    fullDataIdInfo = new FullDataIdInfo();
                    Serializer.Deserialize(reader.BaseStream, fullDataIdInfo);
                }
            }
        }
Example #28
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //Metadata
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                Metadata = reader.ReadBytes(len);
            }

            //VirtualCount
            VirtualCount = reader.ReadInt32();

            if (version >= 2)
            {
                //MetadataPropertyCollection
                if (reader.ReadBoolean())
                {
                    MetadataPropertyCollection = new MetadataPropertyCollection();
                    Serializer.Deserialize(reader.BaseStream, MetadataPropertyCollection);
                }
            }
        }
Example #29
0
        public virtual void Deserialize(IPrimitiveReader reader, int version)
        {
            //TargetIndexName
            targetIndexName = reader.ReadString();

            //IndexIdList
            ushort count = reader.ReadUInt16();

            if (count > 0)
            {
                indexIdList = new List <byte[]>(count);
                ushort len;
                for (ushort i = 0; i < count; i++)
                {
                    len = reader.ReadUInt16();
                    if (len > 0)
                    {
                        indexIdList.Add(reader.ReadBytes(len));
                    }
                }
            }

            //ExcludeData
            excludeData = reader.ReadBoolean();

            //GetIndexHeader
            getIndexHeader = reader.ReadBoolean();

            //PrimaryIdList
            count = reader.ReadUInt16();
            if (count > 0)
            {
                primaryIdList = new List <int>(count);
                for (ushort i = 0; i < count; i++)
                {
                    primaryIdList.Add(reader.ReadInt32());
                }
            }

            //Filter
            byte b = reader.ReadByte();

            if (b != 0)
            {
                FilterType filterType = (FilterType)b;
                filter = FilterFactory.CreateFilter(reader, filterType);
            }

            //IndexIdParamsMapping
            count = reader.ReadUInt16();
            if (count > 0)
            {
                intersectionQueryParamsMapping = new Dictionary <byte[], IntersectionQueryParams>(count, new ByteArrayEqualityComparer());
                byte[] indexId;
                IntersectionQueryParams intersectionQueryParam;
                ushort len;

                for (ushort i = 0; i < count; i++)
                {
                    len     = reader.ReadUInt16();
                    indexId = null;
                    if (len > 0)
                    {
                        indexId = reader.ReadBytes(len);

                        intersectionQueryParam = new IntersectionQueryParams();
                        Serializer.Deserialize(reader.BaseStream, intersectionQueryParam);

                        intersectionQueryParamsMapping.Add(indexId, intersectionQueryParam);
                    }
                }
            }

            if (version >= 2)
            {
                //FullDataIdInfo
                fullDataIdInfo = new FullDataIdInfo();
                Serializer.Deserialize(reader.BaseStream, fullDataIdInfo);
            }
        }
Example #30
0
		public void Deserialize(IPrimitiveReader reader, int version)
		{
			//IndexId
			ushort len = reader.ReadUInt16();
			if (len > 0)
			{
				indexId = reader.ReadBytes(len);
			}

			//TargetIndexName
			targetIndexName = reader.ReadString();

			//IndexTagMapping
			ushort count = reader.ReadUInt16();
			indexTagMapping = new Dictionary<string, List<string>>(count);
			if (count > 0)
			{
				string indexName;
				ushort tagNameListCount;
				List<string> tagNameList;

				for (ushort i = 0; i < count; i++)
				{
					indexName = reader.ReadString();
					tagNameListCount = reader.ReadUInt16();
					tagNameList = new List<string>();
					for (ushort j = 0; j < tagNameListCount; j++)
					{
						tagNameList.Add(reader.ReadString());
					}
					indexTagMapping.Add(indexName, tagNameList);
				}
			}

			//AddList
			int listCount = reader.ReadInt32();
			addList = new List<IndexDataItem>(listCount);
			IndexDataItem indexDataItem;
			for (int i = 0; i < listCount; i++)
			{
				indexDataItem = new IndexDataItem();
				indexDataItem.Deserialize(reader);
				addList.Add(indexDataItem);
			}

			//DeleteList
			listCount = reader.ReadInt32();
			deleteList = new List<IndexItem>(listCount);
			IndexItem indexItem;
			for (int i = 0; i < listCount; i++)
			{
				indexItem = new IndexItem();
				indexItem.Deserialize(reader);
				deleteList.Add(indexItem);
			}

			//Metadata
			len = reader.ReadUInt16();
			if (len > 0)
			{
				metadata = reader.ReadBytes(len);
			}

			//UpdateMetadata
			updateMetadata = reader.ReadBoolean();

			//ReplaceFullIndex
			replaceFullIndex = reader.ReadBoolean();

            if (version >= 2)
            {
                //PreserveData
                preserveData = reader.ReadBoolean();
            }

            if(version >= 3)
            {
                //IndexVirtualCountMapping
                count = reader.ReadUInt16();
                if (count > 0)
                {
                    indexVirtualCountMapping = new Dictionary<string, int>(count);
                    string indexName;
                    int virtualCount;

                    for (ushort i = 0; i < count; i++)
                    {
                        indexName = reader.ReadString();
                        virtualCount = reader.ReadInt32();
                        indexVirtualCountMapping.Add(indexName, virtualCount);
                    }
                }
            }

            if (version >= 4)
            {
                //PrimaryId
                primaryId = reader.ReadInt32();
            }
		}
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //IndexId
            ushort len = reader.ReadUInt16();
            if (len > 0)
            {
                indexId = reader.ReadBytes(len);
            }

            //FirstPageSize
            firstPageSize = reader.ReadInt32();

            //LastPageSize
            lastPageSize = reader.ReadInt32();

            //TargetIndexName
            targetIndexName = reader.ReadString();

            //Read a byte to account for deprecated CriterionList
            reader.ReadByte();

            //ExcludeData
            excludeData = reader.ReadBoolean();

            //GetMetadata
            getMetadata = reader.ReadBoolean();

            if (version >= 2)
            {
                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType)b;
                    filter = FilterFactory.CreateFilter(reader, filterType);
                }
            }

            if(version >= 3)
            {
                //FullDataIdInfo
                fullDataIdInfo = new FullDataIdInfo();
                Serializer.Deserialize(reader.BaseStream, fullDataIdInfo);
            }
        }
Example #32
0
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //IndexId
                ushort len = reader.ReadUInt16();
                if (len > 0)
                {
                    indexId = reader.ReadBytes(len);
                }

                //Count
                count = reader.ReadInt32();

                //TargetIndexName
                targetIndexName = reader.ReadString();

                //ExcludeData
                excludeData = reader.ReadBoolean();

                //GetMetadata
                getMetadata = reader.ReadBoolean();

                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType) b;
                    filter = FilterFactory.CreateFilter(reader, filterType);
                }

                if (version >= 2)
                {
                    //FullDataIdInfo
                    fullDataIdInfo = new FullDataIdInfo();
                    Serializer.Deserialize(reader.BaseStream, fullDataIdInfo);
                }
            }
        }
        /// <summary>
        /// Deserialize the class data from a stream.
        /// </summary>
        /// <param name="reader">The <see cref="IPrimitiveReader"/> that extracts used to extra data from a stream.</param>
        /// <param name="version">The value of <see cref="CurrentVersion"/> that was written to the stream when it was originally serialized to a stream;
        /// the version of the <paramref name="reader"/> data.</param>
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //Metadata
            ushort len = reader.ReadUInt16();
            if (len > 0)
            {
                Metadata = reader.ReadBytes(len);
            }

            //VirtualCount
            if (version >= 2)
            {
                virtualCount = reader.ReadInt32();
            }

            //Count
            outDeserializationContext = new OutDeserializationContext { TotalCount = reader.ReadInt32() };

            if (InDeserializationContext.DeserializeHeaderOnly)
            {
                //Note: If InDeserializationContext.DeserializeHeaderOnly property is set then InDeserializationContext.PartialByteArray shall hold all CacheIndexInternal 
                //payload except metadata and header (just virtual count for now). This code path will only be used if just
                //header info like virtual count needs to be updated keeping rest of the index untouched.
                //InDeserializationContext.PartialByteArray shall be used in Serialize code
                outDeserializationContext.UnserializedCacheIndexInternal =
                    new byte[(int)reader.BaseStream.Length - (int)reader.BaseStream.Position + 1];
                reader.BaseStream.Read(outDeserializationContext.UnserializedCacheIndexInternal, 0, outDeserializationContext.UnserializedCacheIndexInternal.Length);
            }
            else
            {
                int actualItemCount = outDeserializationContext.TotalCount;

                //this.InDeserializationContext.MaxItemsPerIndex = 0 indicates need to extract all items
                //this.InDeserializationContext.MaxItemsPerIndex > 0 indicates need to extract only number of items indicated by InDeserializationContext.MaxItemsPerIndex
                if (InDeserializationContext.MaxItemsPerIndex > 0)
                {
                    if (InDeserializationContext.MaxItemsPerIndex < outDeserializationContext.TotalCount)
                    {
                        actualItemCount = InDeserializationContext.MaxItemsPerIndex;
                    }
                }

                #region Populate InternalItemList

                byte[] itemId;
                InternalItem internalItem;
                bool enterConditionPassed = false;

                InternalItemList = new InternalItemList();

                // Note: ---- Termination condition of the loop
                // For full index extraction loop shall terminate because of condition : internalItemList.Count < actualItemCount
                // For partial index extraction loop shall terminate because of following conditions 
                //				a)  i < InDeserializationContext.TotalCount (when no sufficient items are found) OR
                //				b)  internalItemList.Count < actualItemCount (Item extraction cap is reached)																					
                int i = 0;
                while (InternalItemList.Count < actualItemCount && i < outDeserializationContext.TotalCount)
                {
                    i++;

                    #region Deserialize ItemId

                    len = reader.ReadUInt16();
                    if (len > 0)
                    {
                        itemId = reader.ReadBytes(len);
                    }
                    else
                    {
                        throw new Exception("Invalid ItemId - is null or length is zero for IndexId : " +
                                            IndexCacheUtils.GetReadableByteArray(InDeserializationContext.IndexId));
                    }

                    #endregion

                    #region Process IndexCondition

                    if (InDeserializationContext.EnterCondition != null || InDeserializationContext.ExitCondition != null)
                    {
                        #region Have Enter/Exit Condition

                        if (InDeserializationContext.PrimarySortInfo.IsTag == false)
                        {
                            #region Sort by ItemId

                            if (InDeserializationContext.EnterCondition != null && enterConditionPassed == false)
                            {
                                #region enter condition processing

                                if (InDeserializationContext.EnterCondition.Process(itemId))
                                {
                                    enterConditionPassed = true;
                                    internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                                    ApplyFilterAndAddItem(internalItem);
                                }
                                else
                                {
                                    SkipDeserializeInternalItem(reader);
                                    // no filter processing required
                                }

                                #endregion
                            }
                            else if (InDeserializationContext.ExitCondition != null)
                            {
                                #region exit condition processing

                                if (InDeserializationContext.ExitCondition.Process(itemId))
                                {
                                    // since item passed exit filter, we keep it.
                                    internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                                    ApplyFilterAndAddItem(internalItem);
                                }
                                else
                                {
                                    // no need to search beyond this point
                                    break;
                                }

                                #endregion
                            }
                            else if (InDeserializationContext.EnterCondition != null && enterConditionPassed && InDeserializationContext.ExitCondition == null)
                            {
                                #region enter condition processing when no exit condition exists

                                internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                                ApplyFilterAndAddItem(internalItem);

                                #endregion
                            }

                            #endregion
                        }
                        else
                        {
                            byte[] tagValue;

                            #region Deserialize InternalItem and fetch PrimarySortTag value

                            internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                            if (!internalItem.TryGetTagValue(InDeserializationContext.PrimarySortInfo.FieldName, out tagValue))
                            {
                                throw new Exception("PrimarySortTag Not found:  " + InDeserializationContext.PrimarySortInfo.FieldName);
                            }

                            #endregion

                            #region Sort by Tag

                            if (InDeserializationContext.EnterCondition != null && enterConditionPassed == false)
                            {
                                #region enter condition processing

                                if (InDeserializationContext.EnterCondition.Process(tagValue))
                                {
                                    enterConditionPassed = true;
                                    ApplyFilterAndAddItem(internalItem);
                                }

                                #endregion
                            }
                            else if (InDeserializationContext.ExitCondition != null)
                            {
                                #region exit condition processing

                                if (InDeserializationContext.ExitCondition.Process(tagValue))
                                {
                                    // since item passed exit filter, we keep it.
                                    ApplyFilterAndAddItem(internalItem);
                                }
                                else
                                {
                                    // no need to search beyond this point
                                    break;

                                }

                                #endregion
                            }
                            else if (InDeserializationContext.EnterCondition != null && enterConditionPassed && InDeserializationContext.ExitCondition == null)
                            {
                                #region enter condition processing when no exit condition exists

                                ApplyFilterAndAddItem(internalItem);

                                #endregion
                            }

                            #endregion
                        }

                        #endregion
                    }
                    else
                    {
                        #region No Enter/Exit Condition

                        internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                        ApplyFilterAndAddItem(internalItem);

                        #endregion
                    }

                    #endregion
                }

                //Set ReadItemCount on OutDeserializationContext
                outDeserializationContext.ReadItemCount = i;

                #endregion
            }
        }
        public virtual void Deserialize(IPrimitiveReader reader, int version)
        {
            //TargetIndexName
            targetIndexName = reader.ReadString();

            //IndexIdList
            ushort count = reader.ReadUInt16();
            if (count > 0)
            {
                indexIdList = new List<byte[]>(count);
                ushort len;
                for (ushort i = 0; i < count; i++)
                {
                    len = reader.ReadUInt16();
                    if (len > 0)
                    {
                        indexIdList.Add(reader.ReadBytes(len));
                    }
                }
            }

            //ExcludeData
            excludeData = reader.ReadBoolean();

            //GetIndexHeader
            getIndexHeader = reader.ReadBoolean();

            //PrimaryIdList
            count = reader.ReadUInt16();
            if (count > 0)
            {
                primaryIdList = new List<int>(count);
                for (ushort i = 0; i < count; i++)
                {
                    primaryIdList.Add(reader.ReadInt32());
                }
            }

            //Filter
            byte b = reader.ReadByte();
            if (b != 0)
            {
                FilterType filterType = (FilterType)b;
                filter = FilterFactory.CreateFilter(reader, filterType);
            }

            //IndexIdParamsMapping
            count = reader.ReadUInt16();
            if (count > 0)
            {
                intersectionQueryParamsMapping = new Dictionary<byte[], IntersectionQueryParams>(count, new ByteArrayEqualityComparer());
                byte[] indexId;
                IntersectionQueryParams intersectionQueryParam;
                ushort len;

                for (ushort i = 0; i < count; i++)
                {
                    len = reader.ReadUInt16();
                    indexId = null;
                    if (len > 0)
                    {
                        indexId = reader.ReadBytes(len);

                        intersectionQueryParam = new IntersectionQueryParams();
                        Serializer.Deserialize(reader.BaseStream, intersectionQueryParam);

                        intersectionQueryParamsMapping.Add(indexId, intersectionQueryParam);
                    }
                }
            }

            if (version >= 2)
            {
                //FullDataIdInfo
                fullDataIdInfo = new FullDataIdInfo();
                Serializer.Deserialize(reader.BaseStream, fullDataIdInfo);
            }
        }
        public override void Deserialize(IPrimitiveReader reader, int version)
        {
            //ResultItemList
            int listCount = reader.ReadInt32();
            ResultItemList = new List<ResultItem>(listCount);
            if (listCount > 0)
            {
                ResultItem resultItem;
                for (int i = 0; i < listCount; i++)
                {
                    resultItem = new ResultItem();
                    resultItem.Deserialize(reader);
                    ResultItemList.Add(resultItem);
                }
            }

            //IndexIdIndexHeaderMapping
            ushort count = reader.ReadUInt16();
            if (count > 0)
            {
                IndexIdIndexHeaderMapping = new Dictionary<byte[], IndexHeader>(count, new ByteArrayEqualityComparer());
                byte[] indexId;
                IndexHeader indexHeader;
                ushort len;

                for (ushort i = 0; i < count; i++)
                {
                    len = reader.ReadUInt16();
                    indexId = null;
                    if (len > 0)
                    {
                        indexId = reader.ReadBytes(len);
                    }
                    indexHeader = new IndexHeader();
                    Serializer.Deserialize(reader.BaseStream, indexHeader);

                    IndexIdIndexHeaderMapping.Add(indexId, indexHeader);
                }
            }

            //TotalCount
            TotalCount = reader.ReadInt32();

            //IsTagPrimarySort
            IsTagPrimarySort = reader.ReadBoolean();

            //SortFieldName
            SortFieldName = reader.ReadString();

            //SortOrderList
            count = reader.ReadUInt16();
            SortOrderList = new List<SortOrder>(count);
            SortOrder sortOrder;
            for (int i = 0; i < count; i++)
            {
                sortOrder = new SortOrder();
                sortOrder.Deserialize(reader);
                SortOrderList.Add(sortOrder);
            }

            //ExceptionInfo
            ExceptionInfo = reader.ReadString();

            //AdditionalAvailableItemCount
            AdditionalAvailableItemCount = reader.ReadInt32();
        }
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //MaxItems
                maxItems = reader.ReadInt32();

                //Filter
                byte b = reader.ReadByte();
                if (b != 0)
                {
                    FilterType filterType = (FilterType) b;
                    filter = FilterFactory.CreateFilter(reader, filterType);
                }
            }
        }
		public void Deserialize(IPrimitiveReader reader, int version)
		{
            //MultiItemResult
            if (reader.ReadByte() != 0)
            {
                multiItemResult = new MultiItemResult();
                multiItemResult.Deserialize(reader);
            }

            //Metadata
            ushort len = reader.ReadUInt16();
            if (len > 0)
            {
                metadata = reader.ReadBytes(len);
            }

            //IndexSize
            indexSize = reader.ReadInt32();

            //IndexExists
            indexExists = reader.ReadBoolean();

            //ExceptionInfo
            exceptionInfo = reader.ReadString();

            //VirtualCount
            if(version >= 2)
            {
                virtualCount = reader.ReadInt32();
            }
        }
        /// <summary>
        /// Deserializes the internal item.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="inDeserializationContext">The in deserialization context.</param>
        /// <param name="reader">The reader.</param>
        /// <returns>InternalItem</returns>
        private static InternalItem DeserializeInternalItem(byte[] itemId, InDeserializationContext inDeserializationContext, IPrimitiveReader reader)
        {
            byte kvpListCount = reader.ReadByte();

            List<KeyValuePair<int, byte[]>> kvpList = null;
            if (kvpListCount > 0)
            {
                kvpList = new List<KeyValuePair<int, byte[]>>(kvpListCount);
                for (byte j = 0; j < kvpListCount; j++)
                {
                    int tagHashCode = reader.ReadInt32();
                    ushort tagValueLen = reader.ReadUInt16();
                    byte[] tagValue = null;
                    if (tagValueLen > 0)
                    {
                        tagValue = reader.ReadBytes(tagValueLen);
                        if (inDeserializationContext.StringHashCodeDictionary != null &&
                            inDeserializationContext.StringHashCodeDictionary.Count > 0 &&
                            inDeserializationContext.StringHashCodeDictionary.ContainsKey(tagHashCode))
                        {
                            tagValue =
                                inDeserializationContext.StringHashCollection.GetStringByteArray(
                                    inDeserializationContext.TypeId, tagValue);
                        }
                    }
                    kvpList.Add(new KeyValuePair<int, byte[]>(tagHashCode, tagValue));
                }
            }
            return new InternalItem { ItemId = itemId, TagList = kvpList };
        }
        public override void Deserialize(IPrimitiveReader reader, int version)
        {
            //Offset
            Offset = reader.ReadInt32();

            //Span
            Span = reader.ReadInt32();

            //TargetIndexName
            TargetIndexName = reader.ReadString();

            //TagsFromIndexes
            ushort count = reader.ReadUInt16();

            if (count > 0)
            {
                TagsFromIndexes = new List <string>(count);
                for (ushort i = 0; i < count; i++)
                {
                    TagsFromIndexes.Add(reader.ReadString());
                }
            }

            //TagSort
            if (reader.ReadByte() != 0)
            {
                TagSort = new TagSort();
                Serializer.Deserialize(reader.BaseStream, TagSort);
            }

            //IndexIdList
            count = reader.ReadUInt16();
            if (count > 0)
            {
                IndexIdList = new List <byte[]>(count);
                ushort len;
                for (ushort i = 0; i < count; i++)
                {
                    len = reader.ReadUInt16();
                    if (len > 0)
                    {
                        IndexIdList.Add(reader.ReadBytes(len));
                    }
                }
            }

            //Read a byte to account for deprecated CriterionList
            reader.ReadByte();

            //MaxItemsPerIndex
            MaxItems = reader.ReadInt32();

            //ExcludeData
            ExcludeData = reader.ReadBoolean();

            //GetIndexHeader
            GetIndexHeader = reader.ReadBoolean();

            //GetPageableItemCount
            GetAdditionalAvailableItemCount = reader.ReadBoolean();

            //PrimaryIdList
            count = reader.ReadUInt16();
            if (count > 0)
            {
                PrimaryIdList = new List <int>(count);
                for (ushort i = 0; i < count; i++)
                {
                    PrimaryIdList.Add(reader.ReadInt32());
                }
            }

            //Filter
            byte b = reader.ReadByte();

            if (b != 0)
            {
                FilterType filterType = (FilterType)b;
                Filter = FilterFactory.CreateFilter(reader, filterType);
            }

            //IndexIdParamsMapping
            count = reader.ReadUInt16();
            if (count > 0)
            {
                IndexIdParamsMapping = new Dictionary <byte[], IndexIdParams>(count, new ByteArrayEqualityComparer());
                byte[]        indexId;
                IndexIdParams indexIdParam;
                ushort        len;

                for (ushort i = 0; i < count; i++)
                {
                    len     = reader.ReadUInt16();
                    indexId = null;
                    if (len > 0)
                    {
                        indexId = reader.ReadBytes(len);

                        indexIdParam = new IndexIdParams();
                        Serializer.Deserialize(reader.BaseStream, indexIdParam);

                        IndexIdParamsMapping.Add(indexId, indexIdParam);
                    }
                }
            }

            //FullDataIdInfo
            if (reader.ReadBoolean())
            {
                FullDataIdInfo = new FullDataIdInfo();
                Serializer.Deserialize(reader.BaseStream, FullDataIdInfo);
            }

            //ClientSideSubsetProcessingRequired
            ClientSideSubsetProcessingRequired = reader.ReadBoolean();

            if (version >= 2)
            {
                //CapCondition
                if (reader.ReadBoolean())
                {
                    CapCondition = new CapCondition();
                    Serializer.Deserialize(reader.BaseStream, CapCondition);
                }
            }

            if (version >= 3)
            {
                //GetIndexHeaderType
                GetIndexHeaderType = (GetIndexHeaderType)reader.ReadByte();
            }
        }
        /// <summary>
        /// Deserialize the class data from a stream.
        /// </summary>
        /// <param name="reader">The <see cref="IPrimitiveReader"/> that extracts used to extra data from a stream.</param>
        /// <param name="version">The value of <see cref="CurrentVersion"/> that was written to the stream when it was originally serialized to a stream;
        /// the version of the <paramref name="reader"/> data.</param>
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            //Metadata
            ushort len = reader.ReadUInt16();

            if (len > 0)
            {
                Metadata = reader.ReadBytes(len);
            }

            //VirtualCount
            if (version >= 2)
            {
                virtualCount = reader.ReadInt32();
            }

            //Count
            outDeserializationContext = new OutDeserializationContext {
                TotalCount = reader.ReadInt32()
            };

            if (InDeserializationContext.DeserializeHeaderOnly)
            {
                //Note: If InDeserializationContext.DeserializeHeaderOnly property is set then InDeserializationContext.PartialByteArray shall hold all CacheIndexInternal
                //payload except metadata and header (just virtual count for now). This code path will only be used if just
                //header info like virtual count needs to be updated keeping rest of the index untouched.
                //InDeserializationContext.PartialByteArray shall be used in Serialize code
                outDeserializationContext.UnserializedCacheIndexInternal =
                    new byte[(int)reader.BaseStream.Length - (int)reader.BaseStream.Position + 1];
                reader.BaseStream.Read(outDeserializationContext.UnserializedCacheIndexInternal, 0, outDeserializationContext.UnserializedCacheIndexInternal.Length);
            }
            else
            {
                int actualItemCount = outDeserializationContext.TotalCount;

                //this.InDeserializationContext.MaxItemsPerIndex = 0 indicates need to extract all items
                //this.InDeserializationContext.MaxItemsPerIndex > 0 indicates need to extract only number of items indicated by InDeserializationContext.MaxItemsPerIndex
                if (InDeserializationContext.MaxItemsPerIndex > 0)
                {
                    if (InDeserializationContext.MaxItemsPerIndex < outDeserializationContext.TotalCount)
                    {
                        actualItemCount = InDeserializationContext.MaxItemsPerIndex;
                    }
                }

                #region Populate InternalItemList

                byte[]       itemId;
                InternalItem internalItem;
                bool         enterConditionPassed = false;

                InternalItemList = new InternalItemList();

                // Note: ---- Termination condition of the loop
                // For full index extraction loop shall terminate because of condition : internalItemList.Count < actualItemCount
                // For partial index extraction loop shall terminate because of following conditions
                //				a)  i < InDeserializationContext.TotalCount (when no sufficient items are found) OR
                //				b)  internalItemList.Count < actualItemCount (Item extraction cap is reached)
                int i = 0;
                while (InternalItemList.Count < actualItemCount && i < outDeserializationContext.TotalCount)
                {
                    i++;

                    #region Deserialize ItemId

                    len = reader.ReadUInt16();
                    if (len > 0)
                    {
                        itemId = reader.ReadBytes(len);
                    }
                    else
                    {
                        throw new Exception("Invalid ItemId - is null or length is zero for IndexId : " +
                                            IndexCacheUtils.GetReadableByteArray(InDeserializationContext.IndexId));
                    }

                    #endregion

                    #region Process IndexCondition

                    if (InDeserializationContext.EnterCondition != null || InDeserializationContext.ExitCondition != null)
                    {
                        #region Have Enter/Exit Condition

                        if (InDeserializationContext.PrimarySortInfo.IsTag == false)
                        {
                            #region Sort by ItemId

                            if (InDeserializationContext.EnterCondition != null && enterConditionPassed == false)
                            {
                                #region enter condition processing

                                if (InDeserializationContext.EnterCondition.Process(itemId))
                                {
                                    enterConditionPassed = true;
                                    internalItem         = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                                    ApplyFilterAndAddItem(internalItem);
                                }
                                else
                                {
                                    SkipDeserializeInternalItem(reader);
                                    // no filter processing required
                                }

                                #endregion
                            }
                            else if (InDeserializationContext.ExitCondition != null)
                            {
                                #region exit condition processing

                                if (InDeserializationContext.ExitCondition.Process(itemId))
                                {
                                    // since item passed exit filter, we keep it.
                                    internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                                    ApplyFilterAndAddItem(internalItem);
                                }
                                else
                                {
                                    // no need to search beyond this point
                                    break;
                                }

                                #endregion
                            }
                            else if (InDeserializationContext.EnterCondition != null && enterConditionPassed && InDeserializationContext.ExitCondition == null)
                            {
                                #region enter condition processing when no exit condition exists

                                internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                                ApplyFilterAndAddItem(internalItem);

                                #endregion
                            }

                            #endregion
                        }
                        else
                        {
                            byte[] tagValue;

                            #region Deserialize InternalItem and fetch PrimarySortTag value

                            internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                            if (!internalItem.TryGetTagValue(InDeserializationContext.PrimarySortInfo.FieldName, out tagValue))
                            {
                                throw new Exception("PrimarySortTag Not found:  " + InDeserializationContext.PrimarySortInfo.FieldName);
                            }

                            #endregion

                            #region Sort by Tag

                            if (InDeserializationContext.EnterCondition != null && enterConditionPassed == false)
                            {
                                #region enter condition processing

                                if (InDeserializationContext.EnterCondition.Process(tagValue))
                                {
                                    enterConditionPassed = true;
                                    ApplyFilterAndAddItem(internalItem);
                                }

                                #endregion
                            }
                            else if (InDeserializationContext.ExitCondition != null)
                            {
                                #region exit condition processing

                                if (InDeserializationContext.ExitCondition.Process(tagValue))
                                {
                                    // since item passed exit filter, we keep it.
                                    ApplyFilterAndAddItem(internalItem);
                                }
                                else
                                {
                                    // no need to search beyond this point
                                    break;
                                }

                                #endregion
                            }
                            else if (InDeserializationContext.EnterCondition != null && enterConditionPassed && InDeserializationContext.ExitCondition == null)
                            {
                                #region enter condition processing when no exit condition exists

                                ApplyFilterAndAddItem(internalItem);

                                #endregion
                            }

                            #endregion
                        }

                        #endregion
                    }
                    else
                    {
                        #region No Enter/Exit Condition

                        internalItem = DeserializeInternalItem(itemId, InDeserializationContext, reader);
                        ApplyFilterAndAddItem(internalItem);

                        #endregion
                    }

                    #endregion
                }

                //Set ReadItemCount on OutDeserializationContext
                outDeserializationContext.ReadItemCount = i;

                #endregion
            }
        }
        /// <summary>
        /// Deserialize the class data from a stream.
        /// </summary>
        /// <param name="reader">The <see cref="T:MySpace.Common.IO.IPrimitiveReader"/> that extracts used to extra data from a stream.</param>
        /// <param name="version">The value of <see cref="P:MySpace.Common.IVersionSerializable.CurrentVersion"/> that was written to the stream when it was originally serialized to a stream;
        /// the version of the <paramref name="reader"/> data.</param>
        public void Deserialize(IPrimitiveReader reader, int version)
        {
            using (reader.CreateRegion())
            {
                //FullDataIdType
                FullDataIdType = (FullDataIdType)reader.ReadByte();

                //TagName
                TagName = reader.ReadString();

                if (version >= 2)
                {
                    //Offset
                    reader.ReadInt32();

                    //Count
                    reader.ReadInt32();

                    //DataType
                    DataType = (DataType)reader.ReadByte();

                    //FullDataIdFieldList
                    if (reader.ReadBoolean())
                    {
                        FullDataIdFieldList = new FullDataIdFieldList();
                        Serializer.Deserialize(reader.BaseStream, FullDataIdFieldList);
                    }

                    //FullDataIdPartFormat
                    FullDataIdPartFormat = (FullDataIdPartFormat)reader.ReadByte();
                }
            }
        }
		/// <summary>
		/// Deserializes a color from the reader.
		/// </summary>
		/// <param name="color">The Color struct.</param>
		/// <param name="reader">The primitive reader.</param>
		public static void DeserializeColor(out Color color, IPrimitiveReader reader)
		{
			color = Color.FromArgb(reader.ReadInt32());
		}
 /// <summary>
 /// Reads the serialized header
 /// </summary>
 /// <param name="reader"></param>
 public void Read(IPrimitiveReader reader)
 {
     this.headerPosition = reader.BaseStream.Position;
     this.headerVersion = reader.ReadByte();
     this.headerLength = reader.ReadInt16();
     this.flags = (TypeSerializationHeaderFlags)reader.ReadByte();
     this.dataVersion = reader.ReadByte();
     this.dataMinVersion = reader.ReadByte();
     this.dataLength = reader.ReadInt32();
     this.dataPosition = this.headerPosition + this.headerLength;
     
     if (this.headerVersion > CurrentHeaderVersion)
     {
         throw new ApplicationException("This object was serialized with a newer version of the serialization framework");
     }
     if ((this.flags & ~TypeSerializationHeaderFlags.KnownFlags) != 0)
     {
         throw new ApplicationException("This object was serialized with features that are not supported in this version of the serialization framework");
     }
     
     reader.BaseStream.Seek(this.dataPosition, System.IO.SeekOrigin.Begin);
 }
		public void Deserialize(IPrimitiveReader reader, int version)
		{
			if (version == CurrentVersion)
			{
				MessageType = (MessageType)reader.ReadInt32();
				PayloadLength = reader.ReadInt32();
				int bytesLength = reader.ReadInt32();
				if (bytesLength > -1)
				{
					byte[] bytes = reader.ReadBytes(bytesLength);
					MessageStream = new MemoryStream(bytes);
				}
			}
		}