/// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="T:MySpace.Common.IO.IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //FullDataIdType
                writer.Write((byte)FullDataIdType);

                //TagName
                writer.Write(TagName);

                //Offset
                writer.Write(Offset);

                //Count
                writer.Write(Count);

                //DataType
                writer.Write((byte)DataType);

                //FullDataIdFieldList
                if (FullDataIdFieldList == null)
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    Serializer.Serialize(writer.BaseStream, FullDataIdFieldList);
                }

                //FullDataIdCollectionType
                writer.Write((byte)FullDataIdPartFormat);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="T:MySpace.Common.IO.IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //FieldValue
                if (FieldValue == null || FieldValue.Length == 0)
                {
                    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");
                }
                writer.Write((ushort)FieldValue.Length);
                writer.Write(FieldValue);

                //UseParentFilter
                writer.Write(UseParentFilter);

                //Filter
                if (Filter == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)Filter.FilterType);
                    Serializer.Serialize(writer.BaseStream, Filter);
                }

                //Cap
                writer.Write(Cap);
            }
        }
Exemplo n.º 3
0
        public void Serialize(IPrimitiveWriter writer)
        {
            //IndexExists
            writer.Write(IndexExists);

            //DistinctValueCountPairList
            if (DistinctValueCountMapping == null || DistinctValueCountMapping.Count == 0)
            {
                writer.Write(0);
            }
            else
            {
                writer.Write(DistinctValueCountMapping.Count);
                foreach (KeyValuePair <byte[], int> kvp in DistinctValueCountMapping)
                {
                    //Value
                    if (kvp.Key == null || kvp.Key.Length == 0)
                    {
                        writer.Write((ushort)0);
                    }
                    else
                    {
                        writer.Write((ushort)kvp.Key.Length);
                        writer.Write(kvp.Key);

                        //Count
                        writer.Write(kvp.Value);
                    }
                }
            }

            //ExceptionInfo
            writer.Write(ExceptionInfo);
        }
Exemplo n.º 4
0
        public void Serialize(IPrimitiveWriter writer)
        {
            //Metadata
            if (Metadata == null || Metadata.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)Metadata.Length);
                writer.Write(Metadata);
            }

            //VirtualCount
            writer.Write(VirtualCount);

            //MetadataPropertyCollection
            if (MetadataPropertyCollection == null)
            {
                writer.Write(false);
            }
            else
            {
                writer.Write(true);
                Serializer.Serialize(writer.BaseStream, MetadataPropertyCollection);
            }
        }
        /// <summary>
        /// Serializes a BitArray into the writer.
        /// </summary>
        /// <param name="bitArray">The bit array</param>
        /// <param name="writer">The primitive writer</param>
        public static void SerializeBitArray(BitArray bitArray, IPrimitiveWriter writer)
        {
            // Write the byte length
            if (bitArray == null)
            {
                writer.Write(byte.MaxValue); // byte.MaxValue represents null
                return;
            }

            int currentByteLength = (bitArray.Count + 7) / 8;

            if (currentByteLength >= byte.MaxValue)
            {
                throw new ArgumentException("BitArray is too big to be serialized.", "bitArray");
            }
            // Write the byte length
            writer.Write((byte)currentByteLength);
            // Write only if we need to
            if (currentByteLength > 0)
            {
                // Copy the bitarray into a byte array
                byte[] bitArrayBytes = new byte[currentByteLength];
                bitArray.CopyTo(bitArrayBytes, 0);
                // Serialize
                writer.Write(bitArrayBytes);
            }
        }
Exemplo n.º 6
0
        public void Serialize(IPrimitiveWriter writer)
        {
            //IndexId
            if (IndexId == null || IndexId.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)IndexId.Length);
                writer.Write(IndexId);
            }

            //FieldName
            writer.Write(FieldName);

            //ItemsToLookUp
            writer.Write(ItemsToLookUp);

            //TargetIndexName
            writer.Write(TargetIndexName);

            //IndexCondition
            if (IndexCondition == null)
            {
                writer.Write(false);
            }
            else
            {
                writer.Write(true);
                Serializer.Serialize(writer.BaseStream, IndexCondition);
            }
        }
Exemplo n.º 7
0
        public void Serialize(IPrimitiveWriter writer)
        {
            //IndexDataItem List
            if (Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)Count);
                foreach (IndexDataItem indexDataItem in this)
                {
                    indexDataItem.Serialize(writer);
                }

                //IndexId
                if (indexId == null || indexId.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)indexId.Length);
                    writer.Write(indexId);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Serializes an object
        /// </summary>
        /// <param name="stream">The target stream</param>
        /// <param name="instance">The object to serialize</param>
        /// <param name="flags">One or more <see cref="SerializedFlags"/> options</param>
        public static void Serialize <T>(
            Stream stream,
            T instance,
            SerializerFlags flags,
            CompressionImplementation compression
            )
        {
            IPrimitiveWriter writer = SerializerFactory.GetWriter(stream);

            //  Check parameters
            Debug.Assert(stream != null, "Input stream is null");
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (instance == null)
            {
                return; // Nothing to do
            }

            Serialize <T>(writer, instance, flags);

            //  Compress result if requested
            if ((flags & SerializerFlags.Compress) != 0)
            {
                byte[] bytes = GetBytes(stream, (int)stream.Length);

                bytes = Compressor.GetInstance().Compress(bytes, compression);

                stream.Seek(0, SeekOrigin.Begin);
                stream.SetLength(bytes.Length);
                stream.Write(bytes, 0, (int)bytes.Length);
            }
        }
Exemplo n.º 9
0
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //InclusiveMaxValue
                if (InclusiveMaxValue == null || InclusiveMaxValue.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)InclusiveMaxValue.Length);
                    writer.Write(InclusiveMaxValue);
                }

                //InclusiveMinvalue
                if (InclusiveMinValue == null || InclusiveMinValue.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)InclusiveMinValue.Length);
                    writer.Write(InclusiveMinValue);
                }
            }
        }
Exemplo n.º 10
0
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //Filter
                if (filter == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)filter.FilterType);
                    Serializer.Serialize(writer.BaseStream, filter);
                }

                //Count
                writer.Write(Count);

                //IndexCondition
                if (IndexCondition == null)
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    Serializer.Serialize(writer.BaseStream, IndexCondition);
                }
            }
        }
Exemplo n.º 11
0
        public void WriteTo(IPrimitiveWriter writer)
        {
            if (_types.Count == 0)
            {
                writer.WriteVarInt32(0);
                return;
            }

            int nextAssemblyId            = 0;
            var orderedAssemblyNames      = new List <string>();
            var indexedAssemblyNames      = new Dictionary <string, int>();
            var typesToWrite              = new string [_types.Count];
            var assemblyReferencesToWrite = new int [_types.Count];

            for (int i = 0; i < _types.Count; ++i)
            {
                int id;
                if (!indexedAssemblyNames.TryGetValue(_types[i].AssemblyName, out id))
                {
                    id = nextAssemblyId++;
                    orderedAssemblyNames.Add(_types[i].AssemblyName);
                    indexedAssemblyNames.Add(_types[i].AssemblyName, id);
                }
                typesToWrite[i] = _types[i].FullTypeName;
                assemblyReferencesToWrite[i] = id;
            }

            WriteSegments(writer, orderedAssemblyNames, '.');
            WriteSegments(writer, typesToWrite, '.');

            for (int i = 0; i < assemblyReferencesToWrite.Length; ++i)
            {
                writer.WriteVarInt32(assemblyReferencesToWrite[i]);
            }
        }
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //InclusiveMaxValue
                if (InclusiveMaxValue == null || InclusiveMaxValue.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)InclusiveMaxValue.Length);
                    writer.Write(InclusiveMaxValue);
                }

                //InclusiveMinvalue
                if (InclusiveMinValue == null || InclusiveMinValue.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)InclusiveMinValue.Length);
                    writer.Write(InclusiveMinValue);
                }
            }
        }
Exemplo n.º 13
0
 internal static long BeginWrite(IPrimitiveWriter writer, int version, int minVersion)
 {
     writer.WriteVarInt32(version);
     writer.WriteVarInt32(minVersion);
     writer.Write(-1);             // reserve
     return(writer.BaseStream.Position);
 }
        /// <summary>
        /// Serializes a BitArray into the writer.
        /// </summary>
        /// <param name="bitArray">The bit array</param>
        /// <param name="writer">The primitive writer</param>
        public static void SerializeBitArray(BitArray bitArray, IPrimitiveWriter writer)
        {
            // Write the byte length
            if (bitArray == null)
            {
                writer.Write(byte.MaxValue); // byte.MaxValue represents null
                return;
            }

            int currentByteLength = (bitArray.Count + 7) / 8;
            if (currentByteLength >= byte.MaxValue)
            {
                throw new ArgumentException("BitArray is too big to be serialized.", "bitArray");
            }
            // Write the byte length
            writer.Write((byte)currentByteLength);
            // Write only if we need to
            if (currentByteLength > 0)
            {
                // Copy the bitarray into a byte array
                byte[] bitArrayBytes = new byte[currentByteLength];
                bitArray.CopyTo(bitArrayBytes, 0);
                // Serialize
                writer.Write(bitArrayBytes);
            }
        }
        /// <summary>
        /// Writes or updates the serialized header
        /// </summary>
        /// <param name="writer"></param>
        public void Write(IPrimitiveWriter writer)
        {
            long oldPosition = writer.BaseStream.Position;
            bool firstWrite  = this.headerPosition < 0;

            //  Assumes the first time this header is written that
            //  we're adding it to the stream with some data missing
            //  Subsequent writes are intended to update the header
            //  with new info such as the actual data length
            if (firstWrite)
            {
                this.headerPosition = oldPosition;
            }
            else
            {
                writer.BaseStream.Seek(this.headerPosition, System.IO.SeekOrigin.Begin);
            }

            writer.Write(this.headerVersion);
            writer.Write(this.headerLength);
            writer.Write((byte)this.flags);
            writer.Write(this.dataVersion);
            writer.Write(this.dataMinVersion);
            writer.Write(this.dataLength);

            if (firstWrite)
            {
                this.dataPosition = writer.BaseStream.Position;
                this.headerLength = (short)(this.dataPosition - this.headerPosition);
            }
            else
            {
                writer.BaseStream.Seek(oldPosition, System.IO.SeekOrigin.Begin);
            }
        }
Exemplo n.º 16
0
        //***************************************************************
        //
        //  Serialize
        //
        /// <summary>
        /// Serializes the name table if it contains any entries
        /// </summary>
        /// <param name="writer"></param>
        public void Serialize(IPrimitiveWriter writer)
        {
            if (this.typeTable == null)
            {
                return;
            }

            long startPosition = writer.BaseStream.Position;

            writer.Write((byte)this.assemblyTable.Count);
            foreach (string assemblyName in this.assemblyTable)
            {
                writer.Write(assemblyName);
            }

            writer.Write((byte)this.namespaceTable.Count);
            foreach (string namespaceName in this.namespaceTable)
            {
                writer.Write(namespaceName);
            }

            writer.Write((byte)this.typeTable.Count);
            foreach (TypeData data in this.typeTable.Values)
            {
                writer.Write(data.Version);
                writer.Write(data.AssemblyIndex);
                writer.Write(data.NamespaceIndex);
                writer.Write(data.TypeName);
            }

            writer.Write((short)(writer.BaseStream.Position - startPosition));
            writer.Write(Signature);
        }
Exemplo n.º 17
0
        public override void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //IndexId
                if (IndexId == null || IndexId.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)IndexId.Length);
                    writer.Write(IndexId);
                }

                //TargetIndexName
                writer.Write(TargetIndexName);

                //DeleteFilter
                if (DeleteFilter == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)DeleteFilter.FilterType);
                    Serializer.Serialize(writer.BaseStream, DeleteFilter);
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Serializes the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        public override void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //IndexId
                if (IndexId == null || IndexId.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)IndexId.Length);
                    writer.Write(IndexId);
                }

                //TargetIndexName
                writer.Write(TargetIndexName);

                //MetadataPropertyCollectionUpdate
                if (MetadataPropertyCollectionUpdate == null)
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    Serializer.Serialize(writer.BaseStream, MetadataPropertyCollectionUpdate);
                }
            }
        }
        public void Serialize(IPrimitiveWriter writer)
        {
            writer.Write(this.pageSize);
            writer.Write(this.pageNum);
            writer.Write(this.minValidDateTime.Ticks);
            writer.Write(IndexIdList.Count);

            if (IndexIdList.Count > 0)
            {
                writer.Write(IndexIdList[0].Length);
                foreach (byte[] indexId in IndexIdList)
                {
                    writer.Write(indexId);
                }
            }

            writer.Write(CacheTypeList.Count);
            if (CacheTypeList.Count > 0)
            {
                foreach (int cacheType in CacheTypeList)
                {
                    writer.Write(cacheType);
                }
            }
        }
Exemplo n.º 20
0
        internal static void EndWrite(IPrimitiveWriter writer, long originalPosition)
        {
            long currentPosition = writer.BaseStream.Position;

            writer.BaseStream.Seek(originalPosition - sizeof(int), SeekOrigin.Begin);
            writer.Write((int)(currentPosition - originalPosition));
            writer.BaseStream.Seek(currentPosition, SeekOrigin.Begin);
        }
Exemplo n.º 21
0
        internal static void EndWrite(IPrimitiveWriter writer, long originalPosition, HeaderFlags flags)
        {
            var currentPosition = writer.BaseStream.Position;

            writer.BaseStream.Seek(originalPosition - 1, SeekOrigin.Begin);
            writer.Write((byte)flags);
            writer.BaseStream.Seek(currentPosition, SeekOrigin.Begin);
        }
Exemplo n.º 22
0
 public void Serialize(IPrimitiveWriter writer)
 {
     using (writer.CreateRegion())
     {
         writer.Write((byte)command.CommandType);
         Serializer.Serialize(writer.BaseStream, command);
     }
 }
Exemplo n.º 23
0
 public override void Serialize(IPrimitiveWriter writer)
 {
     writer.Write(IsEmpty);
     //writer.Write(Id);
     writer.Write(AppId);
     writer.Write(AccessToken);
     writer.Write(ExpireTime);
 }
Exemplo n.º 24
0
        /// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="T:MySpace.Common.IO.IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //GroupingFieldNameList
                if (GroupByFieldNameList == null || GroupByFieldNameList.Count == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)GroupByFieldNameList.Count);
                    for (int i = 0; i < GroupByFieldNameList.Count; i++)
                    {
                        writer.Write(GroupByFieldNameList[i]);
                    }
                }

                //FieldName
                writer.Write(FieldName);

                //FieldValueSet
                if (FieldValueSet == null || FieldValueSet.Count == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)FieldValueSet.Count);
                    foreach (byte[] fieldValue in FieldValueSet)
                    {
                        if (fieldValue == null || fieldValue.Length == 0)
                        {
                            writer.Write((ushort)0);
                        }
                        else
                        {
                            writer.Write((ushort)fieldValue.Length);
                            writer.Write(fieldValue);
                        }
                    }
                }

                //NonGroupingFieldNameList
                if (NonGroupByFieldNameList == null || NonGroupByFieldNameList.Count == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)NonGroupByFieldNameList.Count);
                    for (int i = 0; i < NonGroupByFieldNameList.Count; i++)
                    {
                        writer.Write(NonGroupByFieldNameList[i]);
                    }
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Serializes the specified object <paramref name="o"/> as a string.
        /// </summary>
        /// <param name="o">The object to serialize.</param>
        /// <param name="target">The target where the serialized version will be written.</param>
        /// <param name="settings">The serialization settings to use</param>
        public static void Serialize(object o, IPrimitiveWriter target, SerializationSettings settings = null)
        {
            var ow = new Writer(target)
            {
                Settings = settings
            };

            ow.Write(o);
        }
Exemplo n.º 26
0
 public override void Serialize(IPrimitiveWriter writer)
 {
     writer.Write(IsEmpty);
     writer.Write(Code);
     writer.Write(TitaAppId);
     writer.Write(TenantId);
     writer.Write(UserId);
     writer.Write((short)State);
 }
Exemplo n.º 27
0
        /// <summary>
        /// Serializes an object
        /// </summary>
        /// <param name="writer">The target stream</param>
        /// <param name="instance">The object to serialize. This can be null.</param>
        /// <param name="flags">One or more <see cref="SerializedFlags"/> options</param>
        public static void Serialize <T>(IPrimitiveWriter writer, T instance, SerializerFlags flags)
        {
            TypeSerializationInfo typeInfo = TypeSerializationInfo.GetTypeInfo <T>(instance);
            TypeSerializationArgs args     = new TypeSerializationArgs();

            args.Writer = writer;
            args.Flags  = flags;

            typeInfo.Serialize(instance, args);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectWriter"/> class.
 /// </summary>
 /// <param name="writer">The writer to which the data is written.</param>
 /// <exception cref="System.ArgumentNullException">If the writer is null</exception>
 public ObjectWriter(IPrimitiveWriter writer)
 {
     if (writer == null)
     {
         throw new ArgumentNullException(nameof(writer));
     }
     Writer  = writer;
     Context = new ObjectContext();
     Writer.WriteVInt(VERSION);
 }
Exemplo n.º 29
0
		public void Serialize(IPrimitiveWriter writer)
		{
			//TagName
			writer.Write(tagName);

			//IsTag
			writer.Write(isTag);

			//SortOrder
			sortOrder.Serialize(writer);
		}
Exemplo n.º 30
0
        /// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="T:MySpace.Common.IO.IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //FieldName
                writer.Write(FieldName);

                //FilterCaps
                Serializer.Serialize(writer.BaseStream, FilterCaps);
            }
        }
Exemplo n.º 31
0
        public void Serialize(IPrimitiveWriter writer)
        {
            //TagName
            writer.Write(tagName);

            //IsTag
            writer.Write(isTag);

            //SortOrder
            sortOrder.Serialize(writer);
        }
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //RelatedTypeName
                writer.Write(relatedTypeName);

                //FullDataIdFieldList
                Serializer.Serialize(writer.BaseStream, fullDataIdFieldList);
            }
        }
Exemplo n.º 33
0
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //RelatedTypeName
                writer.Write(relatedTypeName);

                //FullDataIdFieldList
                Serializer.Serialize(writer.BaseStream, fullDataIdFieldList);
            }
        }
Exemplo n.º 34
0
        /// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="T:MySpace.Common.IO.IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //FieldName
                writer.Write(FieldName);

                //FilterCaps
                Serializer.Serialize(writer.BaseStream, FilterCaps);
            }
        }
        public void Serialize(IPrimitiveWriter writer)
        {
            //IndexId
            if (indexId == null || indexId.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)indexId.Length);
                writer.Write(indexId);
            }

            //IndexItemList
            if (indexItemList == null || indexItemList.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)indexItemList.Count);
                foreach (IndexItem indexItem in indexItemList)
                {
                    indexItem.Serialize(writer);
                }
            }

            //TargetIndexName
            writer.Write(targetIndexName);

            //TagsFromIndexes
            if (tagsFromIndexes == null || tagsFromIndexes.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)tagsFromIndexes.Count);
                foreach (string str in tagsFromIndexes)
                {
                    writer.Write(str);
                }
            }

            //ExcludeData
            writer.Write(excludeData);

            //GetMetadata
            writer.Write(getMetadata);

            //FullDataIdInfo
            Serializer.Serialize(writer.BaseStream, fullDataIdInfo);
        }
Exemplo n.º 36
0
		public override void Serialize(IPrimitiveWriter writer)
		{
			base.Serialize(writer);

			//IndexId
			if (indexId == null || indexId.Length == 0)
			{
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)indexId.Length);
				writer.Write(indexId);
			}
		}
Exemplo n.º 37
0
        public override void Serialize(IPrimitiveWriter writer)
        {
            base.Serialize(writer);

            //Data
            if (data == null || data.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)data.Length);
                writer.Write(data);
            }
        }
Exemplo n.º 38
0
        public void Serialize(IPrimitiveWriter writer)
        {
            //Metadata
            if (metadata == null || metadata.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)metadata.Length);
                writer.Write(metadata);
            }

            //VirtualCount
            writer.Write(virtualCount);
        }
 public void Serialize(IPrimitiveWriter writer)
 {
     using (writer.CreateRegion())
     {
         //Filter
         if (filter == null)
         {
             writer.Write((byte)0);
         }
         else
         {
             writer.Write((byte)filter.FilterType);
             Serializer.Serialize(writer.BaseStream, filter);
         }
     }
 }
Exemplo n.º 40
0
        public virtual void Serialize(IPrimitiveWriter writer)
        {
            //ItemId
            if (itemId == null || itemId.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)itemId.Length);
                writer.Write(itemId);
            }

            //Tags
            if (tags == null || tags.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)tags.Count);
                foreach (KeyValuePair<string /*TagName*/, byte[] /*TagValue*/> kvp in tags)
                {
                    writer.Write(kvp.Key);
                    if (kvp.Value == null || kvp.Value.Length == 0)
                    {
                        writer.Write((ushort)0);
                    }
                    else
                    {
                        writer.Write((ushort)kvp.Value.Length);
                        writer.Write(kvp.Value);
                    }
                }
            }

        }
Exemplo n.º 41
0
        /// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="T:MySpace.Common.IO.IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //FullDataIdType
                writer.Write((byte)FullDataIdType);

                //TagName
                writer.Write(TagName);

                //Offset
                writer.Write(Offset);

                //Count
                writer.Write(Count);

                //DataType
                writer.Write((byte)DataType);

                //FullDataIdFieldList
                if (FullDataIdFieldList == null)
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    Serializer.Serialize(writer.BaseStream, FullDataIdFieldList);
                }

                //FullDataIdCollectionType
                writer.Write((byte)FullDataIdPartFormat);
            }
        }
        /// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            //Metadata
            if (Metadata == null || Metadata.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)Metadata.Length);
                writer.Write(Metadata);
            }

            if (!LegacySerializationUtil.Instance.IsSupported(InDeserializationContext.TypeId))
            {
                //VirtualCount
                writer.Write(virtualCount);
            }

            // Note: If InDeserializationContext.DeserializeHeaderOnly property is set then InDeserializationContext.UnserializedCacheIndexInternal shall hold all CacheIndexInternal 
            // payload except metadata and virtual count. This code path will only be used if just header info like 
            // virtual count needs to be updated keeping rest of the index untouched
            if (InDeserializationContext.DeserializeHeaderOnly &&
                outDeserializationContext.UnserializedCacheIndexInternal != null &&
                outDeserializationContext.UnserializedCacheIndexInternal.Length != 0)
            {
                //Count
                writer.Write(outDeserializationContext.TotalCount);

                // UnserializedCacheIndexInternal
                writer.BaseStream.Write(outDeserializationContext.UnserializedCacheIndexInternal, 0, outDeserializationContext.UnserializedCacheIndexInternal.Length);
            }
            else
            {
                //Count
                if (InternalItemList == null || InternalItemList.Count == 0)
                {
                    writer.Write(0);
                }
                else
                {
                    writer.Write(InternalItemList.Count);

                    for (int i = 0; i < InternalItemList.Count; i++)
                    {
                        //Id
                        if (InternalItemList[i].ItemId == null || InternalItemList[i].ItemId.Length == 0)
                        {
                            throw new Exception("Invalid ItemId - is null or length is zero for IndexId : " +
                                                IndexCacheUtils.GetReadableByteArray(InDeserializationContext.IndexId));
                        }
                        writer.Write((ushort)InternalItemList[i].ItemId.Length);
                        writer.Write(InternalItemList[i].ItemId);

                        //(byte)KvpListCount
                        if (InternalItemList[i].TagList == null || InternalItemList[i].TagList.Count == 0)
                        {
                            writer.Write((byte)0);
                        }
                        else
                        {
                            writer.Write((byte)InternalItemList[i].TagList.Count);

                            //KvpList
                            byte[] stringHashValue;
                            foreach (KeyValuePair<int /*TagHashCode*/, byte[] /*TagValue*/> kvp in InternalItemList[i].TagList)
                            {
                                writer.Write(kvp.Key);
                                if (kvp.Value == null || kvp.Value.Length == 0)
                                {
                                    writer.Write((ushort)0);
                                }
                                else
                                {
                                    if (InDeserializationContext.StringHashCodeDictionary != null &&
                                        InDeserializationContext.StringHashCodeDictionary.Count > 0 &&
                                        InDeserializationContext.StringHashCodeDictionary.ContainsKey(kvp.Key))
                                    {
                                        InDeserializationContext.StringHashCollection.AddStringArray(InDeserializationContext.TypeId, kvp.Value);
                                        stringHashValue = StringHashCollection.GetHashCodeByteArray(kvp.Value);
                                        writer.Write((ushort)stringHashValue.Length);
                                        writer.Write(stringHashValue);
                                    }
                                    else
                                    {
                                        writer.Write((ushort)kvp.Value.Length);
                                        writer.Write(kvp.Value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
		public void Serialize(IPrimitiveWriter writer)
		{
			writer.Write((int)MessageType);
			writer.Write(PayloadLength);
			if (MessageStream != null)
			{
				byte[] streamBytes = MessageStream.ToArray();
				writer.Write(streamBytes.Length);
				writer.Write(streamBytes);
			}
			else
			{
				writer.Write(-1);
			}
		}
Exemplo n.º 44
0
        public override void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                writer.Write((ushort) FilterList.Count);

                foreach (Filter filter in FilterList)
                {
                    writer.Write((byte) filter.FilterType);
                    Serializer.Serialize(writer.BaseStream, filter);
                }
            }
        }
Exemplo n.º 45
0
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //IndexId
                if (indexId == null || indexId.Length == 0)
                {
                    writer.Write((ushort) 0);
                }
                else
                {
                    writer.Write((ushort) indexId.Length);
                    writer.Write(indexId);
                }

                //Count
                writer.Write(count);

                //TargetIndexName
                writer.Write(targetIndexName);

                //ExcludeData
                writer.Write(excludeData);

                //GetMetadata
                writer.Write(getMetadata);

                //Filter
                if (filter == null)
                {
                    writer.Write((byte) 0);
                }
                else
                {
                    writer.Write((byte) filter.FilterType);
                    Serializer.Serialize(writer.BaseStream, filter);
                }

                //FullDataIdInfo
                Serializer.Serialize(writer.BaseStream, fullDataIdInfo);
            }
        }
Exemplo n.º 46
0
 public abstract void Serialize(IPrimitiveWriter writer);
		/// <summary>
		/// Serializes a color into the writer.
		/// </summary>
		/// <param name="color">The Color struct.</param>
		/// <param name="writer">The primitive writer.</param>
		public static void SerializeColor(Color color, IPrimitiveWriter writer)
		{
			writer.Write(color.ToArgb());
		}
Exemplo n.º 48
0
        /// <summary>
        /// Serializes the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        public override void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //FieldName
                writer.Write(FieldName);

                //IsTag
                writer.Write(IsTag);

                //Operation
                writer.Write((byte)Operation);

                //Value
                if (Value == null || Value.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)Value.Length);
                    writer.Write(Value);
                }

                //DataType
                writer.Write((byte)DataType);

                //MatchValue
                if (ExpectedBitwiseResult == null || ExpectedBitwiseResult.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)ExpectedBitwiseResult.Length);
                    writer.Write(ExpectedBitwiseResult);
                }

                //ShiftBy
                writer.Write(ShiftBy);
            }
        }
 /// <summary>
 /// Writes or updates the serialized header
 /// </summary>
 /// <param name="writer"></param>
 public void Write(IPrimitiveWriter writer)
 {
     long    oldPosition = writer.BaseStream.Position;
     bool    firstWrite = this.headerPosition < 0;
     
     //  Assumes the first time this header is written that
     //  we're adding it to the stream with some data missing
     //  Subsequent writes are intended to update the header
     //  with new info such as the actual data length
     if (firstWrite)
     {
         this.headerPosition = oldPosition;
     }
     else
     {
         writer.BaseStream.Seek(this.headerPosition, System.IO.SeekOrigin.Begin);
     }
     
     writer.Write(this.headerVersion);
     writer.Write(this.headerLength);
     writer.Write((byte)this.flags);
     writer.Write(this.dataVersion);
     writer.Write(this.dataMinVersion);
     writer.Write(this.dataLength);
     
     if (firstWrite)
     {
         this.dataPosition = writer.BaseStream.Position;
         this.headerLength = (short)(this.dataPosition - this.headerPosition);
     }
     else
     {
         writer.BaseStream.Seek(oldPosition, System.IO.SeekOrigin.Begin);
     }
 }
Exemplo n.º 50
0
        public override void Serialize(IPrimitiveWriter writer)
        {
            //ResultItemList
            if (ResultItemList == null || ResultItemList.Count == 0)
            {
                writer.Write(0);
            }
            else
            {
                writer.Write(ResultItemList.Count);
                foreach (ResultItem resultItem in ResultItemList)
                {
                    resultItem.Serialize(writer);
                }
            }

            //IndexIdIndexHeaderMapping
            if (IndexIdIndexHeaderMapping == null || IndexIdIndexHeaderMapping.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)IndexIdIndexHeaderMapping.Count);
                foreach (KeyValuePair<byte[] /*IndexId*/, IndexHeader /*IndexHeader*/> kvp in IndexIdIndexHeaderMapping)
                {
                    //IndexId
                    if (kvp.Key == null || kvp.Key.Length == 0)
                    {
                        writer.Write((ushort)0);
                    }
                    else
                    {
                        writer.Write((ushort)kvp.Key.Length);
                        writer.Write(kvp.Key);
                    }

                    //IndexHeader
                    Serializer.Serialize(writer, kvp.Value);
                }
            }

            //TotalCount
            writer.Write(TotalCount);

            //IsTagPrimarySort
            writer.Write(IsTagPrimarySort);

            //SortFieldName
            // Note : this field will only be needed if PrimarySort field is tag
            if (IsTagPrimarySort)
            {
                writer.Write(SortFieldName);
            }
            else
            {
                writer.Write("");
            }

            //SortOrderList
            if (SortOrderList == null || SortOrderList.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)SortOrderList.Count);
                foreach (SortOrder sortOrder in SortOrderList)
                {
                    sortOrder.Serialize(writer);
                }
            }

            //ExceptionInfo
            writer.Write(ExceptionInfo);

            //AdditionalAvailableItemCount
            writer.Write(AdditionalAvailableItemCount);
        }
		public void Serialize(IPrimitiveWriter writer)
		{
			//IndexId
			if (indexId == null || indexId.Length == 0)
			{
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)indexId.Length);
				writer.Write(indexId);
			}

			//IndexItemList
            if(indexItemList == null || indexItemList.Count == 0)
            {
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)indexItemList.Count);
                foreach(IndexItem indexItem in indexItemList)
                {
                    indexItem.Serialize(writer);
                }
			}

			//TargetIndexName
			writer.Write(targetIndexName);

			//TagsFromIndexes
			if (tagsFromIndexes == null || tagsFromIndexes.Count == 0)
			{
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)tagsFromIndexes.Count);
				foreach (string str in tagsFromIndexes)
				{
					writer.Write(str);
				}
			}

			//ExcludeData
			writer.Write(excludeData);

			//GetMetadata
			writer.Write(getMetadata);

            //FullDataIdInfo
		    Serializer.Serialize(writer.BaseStream, fullDataIdInfo);
		}
Exemplo n.º 52
0
		public void Serialize(IPrimitiveWriter writer)
		{
			//IndexId
			if (indexId == null || indexId.Length == 0)
			{
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)indexId.Length);
				writer.Write(indexId);
			}

			//TargetIndexName
			writer.Write(targetIndexName);

			//IndexTagMapping
			if (indexTagMapping == null || indexTagMapping.Count == 0)
			{
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)indexTagMapping.Count);
				foreach (KeyValuePair<string /*IndexName*/, List<string> /*TagNameList*/> kvp in indexTagMapping)
				{
					writer.Write(kvp.Key);
					if (kvp.Value == null || kvp.Value.Count == 0)
					{
						writer.Write((ushort)0);
					}
					else
					{
						writer.Write((ushort)kvp.Value.Count);
						foreach (string str in kvp.Value)
						{
							writer.Write(str);
						}
					}
				}
			}

			//AddList
			if (addList == null || addList.Count == 0)
			{
				writer.Write(0);
			}
			else
			{
				writer.Write(addList.Count);
				foreach (IndexDataItem indexDataItem in addList)
				{
					indexDataItem.Serialize(writer);
				}
			}

			//DeleteList
			if (deleteList == null || deleteList.Count == 0)
			{
				writer.Write(0);
			}
			else
			{
				writer.Write(deleteList.Count);
				foreach (IndexItem indexItem in deleteList)
				{
					indexItem.Serialize(writer);
				}
			}

			//Metadata
			if (metadata == null || metadata.Length == 0)
			{
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)metadata.Length);
				writer.Write(metadata);
			}

			//UpdateMetadata
			writer.Write(updateMetadata);

			//ReplaceFullIndex
			writer.Write(replaceFullIndex);

            //PreserveData
            writer.Write(preserveData);

            //IndexVirtualCountMapping
            if (indexVirtualCountMapping == null || indexVirtualCountMapping.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)indexVirtualCountMapping.Count);
                foreach (KeyValuePair<string /*IndexName*/, int /*VirtualCount*/> kvp in indexVirtualCountMapping)
                {
                    writer.Write(kvp.Key);
                    writer.Write(kvp.Value);
                }
            }

            //PrimaryId
            writer.Write(primaryId);
		}
Exemplo n.º 53
0
        public void Serialize(IPrimitiveWriter writer)
        {
            //IndexId
            if (indexId == null || indexId.Length == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)indexId.Length);
                writer.Write(indexId);
            }

            //FirstPageSize
            writer.Write(firstPageSize);

            //LastPageSize
            writer.Write(lastPageSize);

            //TargetIndexName
            writer.Write(targetIndexName);

            //Write a byte to account for deprecated CriterionList
            writer.Write((byte)0);

            //ExcludeData
            writer.Write(excludeData);

            //GetMetadata
            writer.Write(getMetadata);

            //Filter
            if (filter == null)
            {
                writer.Write((byte)0);
            }
            else
            {
                writer.Write((byte)filter.FilterType);
                Serializer.Serialize(writer.BaseStream, filter);
            }

            //FullDataIdInfo
            Serializer.Serialize(writer.BaseStream, fullDataIdInfo);
        }
		public void Serialize(IPrimitiveWriter writer)
		{
            //MultiItemResult
            if(multiItemResult == null || multiItemResult.Count == 0)
            {
                writer.Write((byte)0);
            }
            else
            {
                writer.Write((byte)1);
                multiItemResult.Serialize(writer);
            }

			//Metadata
			if (metadata == null || metadata.Length == 0)
			{
				writer.Write((ushort)0);
			}
			else
			{
				writer.Write((ushort)metadata.Length);
				writer.Write(metadata);
			}

			//IndexSize
			writer.Write(indexSize);

			//IndexExists
			writer.Write(indexExists);

			//ExceptionInfo
			writer.Write(exceptionInfo);

            //VirtualCount
            writer.Write(virtualCount);
		}
 /// <summary>
 /// Set the data length based on the data start position and
 /// current stream position
 /// </summary>
 /// <param name="writer"></param>
 public void UpdateDataLength(IPrimitiveWriter writer)
 {
     this.dataLength = (int)(writer.BaseStream.Position - this.dataPosition);
 }
        public override void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //IndexId
                if (indexId == null || indexId.Length == 0)
                {
                    writer.Write((ushort)0);
                }
                else
                {
                    writer.Write((ushort)indexId.Length);
                    writer.Write(indexId);
                }

                //TargetIndexName
                writer.Write(targetIndexName);

                //DeleteFilter
                if (deleteFilter == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)deleteFilter.FilterType);
                    Serializer.Serialize(writer.BaseStream, deleteFilter);
                }
            }
        }
Exemplo n.º 57
0
 public void Serialize(IPrimitiveWriter writer)
 {
     using (writer.CreateRegion())
     {
         writer.Write((byte)command.CommandType);
         Serializer.Serialize(writer.BaseStream, command);
     }
 }
Exemplo n.º 58
0
        public virtual void Serialize(IPrimitiveWriter writer)
        {
            //TargetIndexName
            writer.Write(targetIndexName);

            //IndexIdList
            if (indexIdList == null || indexIdList.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)indexIdList.Count);
                foreach (byte[] indexId in indexIdList)
                {
                    if (indexId == null || indexId.Length == 0)
                    {
                        writer.Write((ushort)0);
                    }
                    else
                    {
                        writer.Write((ushort)indexId.Length);
                        writer.Write(indexId);
                    }
                }
            }

            //ExcludeData
            writer.Write(excludeData);

            //GetIndexHeader
            writer.Write(getIndexHeader);

            //PrimaryIdList
            if (primaryIdList == null || primaryIdList.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)primaryIdList.Count);
                foreach (int primaryId in primaryIdList)
                {
                    writer.Write(primaryId);
                }
            }

            //Filter
            if (filter == null)
            {
                writer.Write((byte)0);
            }
            else
            {
                writer.Write((byte)filter.FilterType);
                Serializer.Serialize(writer.BaseStream, filter);
            }

            //IndexIdParamsMapping
            if (intersectionQueryParamsMapping == null || intersectionQueryParamsMapping.Count == 0)
            {
                writer.Write((ushort)0);
            }
            else
            {
                writer.Write((ushort)intersectionQueryParamsMapping.Count);
                foreach (KeyValuePair<byte[] /*IndexId*/, IntersectionQueryParams /*IntersectionQueryParams*/> kvp in intersectionQueryParamsMapping)
                {
                    //IndexId
                    if (kvp.Key == null || kvp.Key.Length == 0)
                    {
                        writer.Write((ushort)0);

                        //No need to serialize IntersectionQueryParams
                    }
                    else
                    {
                        writer.Write((ushort)kvp.Key.Length);
                        writer.Write(kvp.Key);

                        //IntersectionQueryParams
                        Serializer.Serialize(writer, kvp.Value);
                    }
                }
            }

            //FullDataIdInfo
            Serializer.Serialize(writer.BaseStream, fullDataIdInfo);
        }