コード例 #1
0
ファイル: ObjectSerializer.cs プロジェクト: ramilbgd/.NET-SDK
        private void WriteObjectMap(IDictionary objectFields, IProtocolFormatter writer)
        {
            int maxInt = -1;

            for (int i = 0; i < objectFields.Count; i++)
            {
                if (!objectFields.Contains(i))
                {
                    break;
                }

                maxInt = i;
            }

            writer.BeginWriteObjectMap(maxInt + 1);

            IEnumerator en = objectFields.Keys.GetEnumerator();

            while (en.MoveNext())
            {
                object fieldName = en.Current;

                if (fieldName.Equals("length"))
                {
                    continue;
                }

                if (Log.isLogging(LoggingConstants.SERIALIZATION))
                {
                    Log.log(LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName);
                }

                writer.WriteFieldName(fieldName.ToString());
                writer.BeginWriteFieldValue();

                MessageWriter.writeObject(objectFields[fieldName], writer);

                writer.EndWriteFieldValue();
            }

            if (maxInt >= 0)
            {
                writer.WriteFieldName("length");
                MessageWriter.writeObject(maxInt + 1, writer);
            }

            writer.EndWriteObjectMap();
        }
コード例 #2
0
ファイル: ObjectSerializer.cs プロジェクト: ramilbgd/.NET-SDK
        public void WriteObject(string className, IDictionary objectFields, IProtocolFormatter writer)
        {
            if (objectFields.Contains("serializeAsArrayMap"))
            {
                objectFields.Remove("serializeAsArrayMap");
                WriteObjectMap(objectFields, writer);
                return;
            }

            if (className != null)
            {
                writer.BeginWriteNamedObject(className, objectFields.Count);
            }
            else
            {
                //writer.BeginWriteObjectMap( objectFields.Count );
                writer.BeginWriteObject(objectFields.Count);
            }

            IEnumerator en = objectFields.Keys.GetEnumerator();

            while (en.MoveNext())
            {
                object fieldName = en.Current;

                if (Log.isLogging(LoggingConstants.SERIALIZATION))
                {
                    Log.log(LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName);
                }

                writer.WriteFieldName(fieldName.ToString());
                writer.BeginWriteFieldValue();

                try
                {
                    MessageWriter.writeObject(objectFields[fieldName], writer);
                }
                catch (Exception exception)
                {
                    if (Log.isLogging(LoggingConstants.ERROR))
                    {
                        Log.log(LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception);
                    }
                }
                finally
                {
                    writer.EndWriteFieldValue();
                }
            }

            if (className != null)
            {
                writer.EndWriteNamedObject();
            }
            else
            {
                //writer.EndWriteObjectMap();
                writer.EndWriteObject();
            }
        }
コード例 #3
0
        public override void write( object obj, IProtocolFormatter writer )
		{
			IDictionary propertyBag = ((AnonymousObject) obj).Properties;
			writer.BeginWriteObject( propertyBag.Count );

			foreach( object key in propertyBag.Keys )
			{
                writer.WriteFieldName( key.ToString() );
                writer.BeginWriteFieldValue();
				MessageWriter.writeObject( propertyBag[ key ], writer );
                writer.EndWriteFieldValue();
			}

            writer.EndWriteObject();
		}
コード例 #4
0
		public void WriteObject( string className, IDictionary objectFields, IProtocolFormatter writer )
		{
    if ( objectFields.Contains( "serializeAsArrayMap" ) )
      {
      objectFields.Remove( "serializeAsArrayMap" );
      WriteObjectMap( objectFields, writer );
      return;
      }

		  if( className != null )
				writer.BeginWriteNamedObject( className, objectFields.Count );
			else
				//writer.BeginWriteObjectMap( objectFields.Count );
                writer.BeginWriteObject( objectFields.Count );

			IEnumerator en = objectFields.Keys.GetEnumerator();

			while( en.MoveNext() )
			{
				object fieldName = en.Current;

				if( Log.isLogging( LoggingConstants.SERIALIZATION ) )
                    Log.log( LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName );

				writer.WriteFieldName( fieldName.ToString() );
				writer.BeginWriteFieldValue();

				try
				{
					MessageWriter.writeObject( objectFields[ fieldName ], writer );
				}
				catch( Exception exception )
				{
					if( Log.isLogging( LoggingConstants.ERROR ) )
						Log.log( LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception );
				}
				finally
				{
					writer.EndWriteFieldValue();
				}
			}
            
			if( className != null )
				writer.EndWriteNamedObject();
			else
				//writer.EndWriteObjectMap();
                writer.EndWriteObject();
		}
コード例 #5
0
        public override void write(object obj, IProtocolFormatter writer)
        {
            IDictionary propertyBag = ((AnonymousObject)obj).Properties;

            writer.BeginWriteObject(propertyBag.Count);

            foreach (object key in propertyBag.Keys)
            {
                writer.WriteFieldName(key.ToString());
                writer.BeginWriteFieldValue();
                MessageWriter.writeObject(propertyBag[key], writer);
                writer.EndWriteFieldValue();
            }

            writer.EndWriteObject();
        }
コード例 #6
0
    private void WriteObjectMap( IDictionary objectFields, IProtocolFormatter writer )
      {
      int maxInt = -1;
      for ( int i = 0; i < objectFields.Count; i++ )
        {
        if ( !objectFields.Contains( i ) )
            break;          

        maxInt = i;
        }

      writer.BeginWriteObjectMap( maxInt + 1 );        

      IEnumerator en = objectFields.Keys.GetEnumerator();

      while ( en.MoveNext() )
        {
        object fieldName = en.Current;

        if ( fieldName.Equals( "length" ) )
          continue;

        if ( Log.isLogging( LoggingConstants.SERIALIZATION ) )
          Log.log( LoggingConstants.SERIALIZATION, "serializing property/field : " + fieldName );

          writer.WriteFieldName( fieldName.ToString() );
          writer.BeginWriteFieldValue();

          MessageWriter.writeObject( objectFields[ fieldName ], writer );

          writer.EndWriteFieldValue();          
        }

        if ( maxInt >= 0 )
          {
          writer.WriteFieldName( "length" );
          MessageWriter.writeObject( maxInt + 1, writer );
          }

        writer.EndWriteObjectMap();        
      }
コード例 #7
0
    public void WriteObject( string className, IDictionary objectFields, IProtocolFormatter writer )
    {
      IEnumerator en = objectFields.Keys.GetEnumerator();
      V3ReferenceCache cache = (V3ReferenceCache) writer.GetReferenceCache();
      String traitsClassId = className;

      if( traitsClassId == null )
      {
        StringBuilder sb = new StringBuilder();

        while( en.MoveNext() )
        {
          sb.Append( en.Current.ToString() );
          sb.Append( "-" );
        }

        traitsClassId = sb.ToString();
        en.Reset();
      }

      if( cache.HasTraits( traitsClassId ) )
      {
        writer.DirectWriteBytes( new byte[] { (byte) Datatypes.OBJECT_DATATYPE_V3 } );
        int traitId = (int) cache.GetTraitsId( traitsClassId );
        byte[] bytes = FlashorbBinaryWriter.GetVarIntBytes( 0x1 | traitId << 2 );
        writer.DirectWriteBytes( bytes );
      }
      else
      {
        writer.BeginWriteNamedObject( className, objectFields.Count );

        if( className == null )
          cache.AddToTraitsCache( traitsClassId );

        while( en.MoveNext() )
        {
          string fieldName = en.Current.ToString();

          if( Log.isLogging( LoggingConstants.DEBUG ) )
            Log.log( LoggingConstants.DEBUG, "serializing property/field : " + fieldName );

          writer.WriteFieldName( fieldName );
        }

        en.Reset();
      }

      while( en.MoveNext() )
      {
        Object fieldName = en.Current;

        if( Log.isLogging( LoggingConstants.DEBUG ) )
          Log.log( LoggingConstants.DEBUG, "serializing property/field : " + fieldName );

        //writer.BeginWriteFieldValue();

        //try
        //{
        //MessageWriter.writeObject( objectFields[ fieldName ], writer );
        //Log.log( "REFCACHE", "WRITING FIELD " + fieldName );
        object obj = objectFields[ fieldName ];
        ITypeWriter typeWriter = MessageWriter.getWriter( obj, writer );
        typeWriter.write( obj, writer );
        //Log.log( "REFCACHE", "DONE WRITING FIELD " + fieldName );
        //}
        //catch( Exception exception )
        //{
        //	if( Log.isLogging( LoggingConstants.ERROR ) )
        //		Log.log( LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception );
        //}
        //finally
        //{
        //	writer.EndWriteFieldValue();
        //}
      }

      writer.EndWriteNamedObject();
    }
コード例 #8
0
        public void WriteObject(string className, IDictionary objectFields, IProtocolFormatter writer)
        {
            IEnumerator      en            = objectFields.Keys.GetEnumerator();
            V3ReferenceCache cache         = (V3ReferenceCache)writer.GetReferenceCache();
            String           traitsClassId = className;

            List <String> toRemove = new List <String>();

            while (en.MoveNext())
            {
                String fieldName = en.Current.ToString();
                object obj       = objectFields[fieldName];

                if (obj != null && obj is ICollection && ((ICollection)obj).Count == 0)
                {
                    toRemove.Add(fieldName);
                    continue;
                }

                if (obj != null && obj.GetType().IsArray&& ((Object[])obj).Length == 0)
                {
                    toRemove.Add(fieldName);
                    continue;
                }
            }

            foreach (Object key in toRemove)
            {
                objectFields.Remove(key);
            }

            en = objectFields.Keys.GetEnumerator();

            if (traitsClassId == null)
            {
                StringBuilder sb = new StringBuilder();

                while (en.MoveNext())
                {
                    sb.Append(en.Current.ToString());
                    sb.Append("-");
                }

                traitsClassId = sb.ToString();
                en.Reset();
            }

            if (cache.HasTraits(traitsClassId))
            {
                writer.DirectWriteBytes(new byte[] { (byte)Datatypes.OBJECT_DATATYPE_V3 });
                int    traitId = (int)cache.GetTraitsId(traitsClassId);
                byte[] bytes   = FlashorbBinaryWriter.GetVarIntBytes(0x1 | traitId << 2);
                writer.DirectWriteBytes(bytes);
            }
            else
            {
                writer.BeginWriteNamedObject(className, objectFields.Count);

                if (className == null)
                {
                    cache.AddToTraitsCache(traitsClassId);
                }

                while (en.MoveNext())
                {
                    string fieldName = en.Current.ToString();

                    if (Log.isLogging(LoggingConstants.DEBUG))
                    {
                        Log.log(LoggingConstants.DEBUG, "serializing property/field : " + fieldName);
                    }

                    writer.WriteFieldName(fieldName);
                }

                en.Reset();
            }

            while (en.MoveNext())
            {
                Object fieldName = en.Current;

                if (Log.isLogging(LoggingConstants.DEBUG))
                {
                    Log.log(LoggingConstants.DEBUG, "serializing property/field : " + fieldName);
                }

                //writer.BeginWriteFieldValue();

                //try
                //{
                //MessageWriter.writeObject( objectFields[ fieldName ], writer );
                //Log.log( "REFCACHE", "WRITING FIELD " + fieldName );
                object obj = objectFields[fieldName];

                if (obj != null && obj is ICollection && ((ICollection)obj).Count == 0)
                {
                    continue;
                }

                if (obj != null && obj.GetType().IsArray&& ((Object[])obj).Length == 0)
                {
                    continue;
                }

                ITypeWriter typeWriter = MessageWriter.getWriter(obj, writer);
                typeWriter.write(obj, writer);
                //Log.log( "REFCACHE", "DONE WRITING FIELD " + fieldName );
                //}
                //catch( Exception exception )
                //{
                //	if( Log.isLogging( LoggingConstants.ERROR ) )
                //		Log.log( LoggingConstants.ERROR, "unable to serialize object's field " + fieldName, exception );
                //}
                //finally
                //{
                //	writer.EndWriteFieldValue();
                //}
            }

            writer.EndWriteNamedObject();
        }