public void write( object obj, IProtocolFormatter writer ) { int refId = -1; ReferenceCache referenceCache = null; if( isReferenceable ) { referenceCache = writer.GetReferenceCache(); refId = referenceCache.GetStringId( obj ); } if( refId != -1 ) { writer.WriteStringReference( refId ); } else { if( isReferenceable ) referenceCache.AddString( obj ); //formatter.getContextWriter().write( obj, formatter ); if( obj is string ) writer.WriteString( (string) obj ); else if( obj is StringBuilder ) writer.WriteString( ((StringBuilder) obj).ToString() ); else if( obj is Char ) writer.WriteString( obj.ToString() ); else if( obj is char[] ) writer.WriteString( new String( (char[]) obj ) ); } }
public void write(object obj, IProtocolFormatter formatter) { ReferenceCache referenceCache = formatter.GetReferenceCache(); int refId = referenceCache.GetObjectId(obj); if (refId != -1) { #if FULL_BUILD if (VectorUtils.IsVector(obj) && formatter is AmfV3Formatter) { Type collectionType = obj.GetType(); AmfV3Formatter amfV3Formatter = (AmfV3Formatter)formatter; if (VectorUtils.isIntType(collectionType)) { amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.INT_VECTOR_V3); } else if (VectorUtils.isUIntType(collectionType)) { amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.UINT_VECTOR_V3); } else if (VectorUtils.isNumberType(collectionType)) { amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.DOUBLE_VECTOR_V3); } else { amfV3Formatter.WriteVarIntWithoutMarker(Datatypes.OBJECT_VECTOR_V3); } amfV3Formatter.WriteVarIntWithoutMarker(refId << 1); } else #endif if (obj is IWebORBArrayCollection || obj is IDictionary) { formatter.WriteObjectReference(refId); } else if (obj is ICollection || obj is Array || obj is IWebORBArray) { formatter.WriteArrayReference(refId); } } else { referenceCache.AddObject(obj); formatter.getContextWriter().write(obj, formatter); } }
public void write( object obj, IProtocolFormatter formatter ) { ReferenceCache referenceCache = formatter.GetReferenceCache(); int refId = referenceCache.GetObjectId( obj ); if( refId != -1 ) { formatter.WriteObjectReference( refId ); } else { referenceCache.AddObject( obj ); formatter.getContextWriter().write( obj, formatter ); } }
public void write(object obj, IProtocolFormatter formatter) { ReferenceCache referenceCache = formatter.GetReferenceCache(); int refId = referenceCache.GetStringId(obj); if (refId != -1) { formatter.WriteStringReference(refId); } else { referenceCache.AddString(obj); formatter.getContextWriter().write(obj, formatter); } }
public virtual void write(object obj, IProtocolFormatter formatter) { ReferenceCache referenceCache = formatter.GetReferenceCache(); DateTime date = (DateTime)obj; int refId = referenceCache.GetObjectId(date.ToUniversalTime()); if (refId != -1) { formatter.WriteDateReference(refId); } else { referenceCache.AddObject(date.ToUniversalTime()); formatter.getContextWriter().write(obj, formatter); } }
public virtual void write( object obj, IProtocolFormatter formatter ) { ReferenceCache referenceCache = formatter.GetReferenceCache(); DateTime date = (DateTime) obj; int refId = referenceCache.GetObjectId( date.ToUniversalTime() ); if( refId != -1 ) { formatter.WriteDateReference( refId ); } else { referenceCache.AddObject( date.ToUniversalTime() ); formatter.getContextWriter().write( obj, formatter ); } }
public void write( object obj, IProtocolFormatter formatter ) { ReferenceCache referenceCache = formatter.GetReferenceCache(); int refId = referenceCache.GetObjectId( obj ); if( refId != -1 ) { #if FULL_BUILD if( VectorUtils.IsVector( obj ) && formatter is AmfV3Formatter ) { Type collectionType = obj.GetType(); AmfV3Formatter amfV3Formatter = (AmfV3Formatter) formatter; if( VectorUtils.isIntType( collectionType ) ) amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.INT_VECTOR_V3 ); else if( VectorUtils.isUIntType( collectionType ) ) amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.UINT_VECTOR_V3 ); else if( VectorUtils.isNumberType( collectionType ) ) amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.DOUBLE_VECTOR_V3 ); else amfV3Formatter.WriteVarIntWithoutMarker( Datatypes.OBJECT_VECTOR_V3 ); amfV3Formatter.WriteVarIntWithoutMarker( refId << 1 ); } else #endif if( obj is IWebORBArrayCollection || obj is IDictionary ) { formatter.WriteObjectReference( refId ); } else if( obj is ICollection || obj is Array || obj is IWebORBArray ) { formatter.WriteArrayReference( refId ); } } else { referenceCache.AddObject( obj ); formatter.getContextWriter().write( obj, formatter ); } }
public void write(object obj, IProtocolFormatter writer) { int refId = -1; ReferenceCache referenceCache = null; if (isReferenceable) { referenceCache = writer.GetReferenceCache(); refId = referenceCache.GetStringId(obj); } if (refId != -1) { writer.WriteStringReference(refId); } else { if (isReferenceable) { referenceCache.AddString(obj); } //formatter.getContextWriter().write( obj, formatter ); if (obj is string) { writer.WriteString((string)obj); } else if (obj is StringBuilder) { writer.WriteString(((StringBuilder)obj).ToString()); } else if (obj is Char) { writer.WriteString(obj.ToString()); } else if (obj is char[]) { writer.WriteString(new String((char[])obj)); } } }
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(); }
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(); }