public void Write(__BinaryWriter sout)
 {
     this.majorVersion = this.binaryFormatterMajorVersion;
     this.minorVersion = this.binaryFormatterMinorVersion;
     sout.WriteByte((byte) this.binaryHeaderEnum);
     sout.WriteInt32(this.topId);
     sout.WriteInt32(this.headerId);
     sout.WriteInt32(this.binaryFormatterMajorVersion);
     sout.WriteInt32(this.binaryFormatterMinorVersion);
 }
Exemplo n.º 2
0
 internal static void WriteStringWithCode(string value, __BinaryWriter sout)
 {
     if (value == null)
     {
         sout.WriteByte((byte)17);
     }
     else
     {
         sout.WriteByte((byte)18);
         sout.WriteString(value);
     }
 }
Exemplo n.º 3
0
 internal static void WriteWithCode(Type type, object value, __BinaryWriter sout)
 {
     if (type == null)
     {
         sout.WriteByte((byte)17);
     }
     else if (type == Converter.typeofString)
     {
         IOUtil.WriteStringWithCode((string)value, sout);
     }
     else
     {
         InternalPrimitiveTypeE code = Converter.ToCode(type);
         sout.WriteByte((byte)code);
         sout.WriteValue(code, value);
     }
 }
 public  void Write(__BinaryWriter sout)
 { 
     majorVersion = binaryFormatterMajorVersion; 
     minorVersion = binaryFormatterMinorVersion;
     sout.WriteByte((Byte)binaryHeaderEnum); 
     sout.WriteInt32(topId);
     sout.WriteInt32(headerId);
     sout.WriteInt32(binaryFormatterMajorVersion);
     sout.WriteInt32(binaryFormatterMinorVersion); 
 }
 public  void Write(__BinaryWriter sout) 
 {
     sout.WriteByte((Byte)BinaryHeaderEnum.MessageEnd); 
 }
 public  void Write(__BinaryWriter sout)
 { 
     sout.WriteByte((Byte)BinaryHeaderEnum.MemberReference); 
     sout.WriteInt32(idRef);
 } 
 public  void Write(__BinaryWriter sout) 
 {
     if (nullCount == 1) 
     { 
         sout.WriteByte((Byte)BinaryHeaderEnum.ObjectNull);
     } 
     else if (nullCount < 256)
     {
         sout.WriteByte((Byte)BinaryHeaderEnum.ObjectNullMultiple256);
         sout.WriteByte((Byte)nullCount); 
         //Console.WriteLine("Write nullCount "+nullCount);
     } 
     else 
     {
         sout.WriteByte((Byte)BinaryHeaderEnum.ObjectNullMultiple); 
         sout.WriteInt32(nullCount);
         //Console.WriteLine("Write nullCount "+nullCount);
     }
 } 
        // Writes the type information on the wire 
        internal static void WriteTypeInfo(BinaryTypeEnum binaryTypeEnum, Object typeInformation, int assemId, __BinaryWriter sout)
        {
            SerTrace.Log( "BinaryConverter", "WriteTypeInfo Entry  ",((Enum)binaryTypeEnum).ToString()," ",typeInformation," assemId ",assemId);
 
            switch (binaryTypeEnum)
            { 
                case BinaryTypeEnum.Primitive: 
                case BinaryTypeEnum.PrimitiveArray:
                    Contract.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null"); 
                    sout.WriteByte((Byte)((InternalPrimitiveTypeE)typeInformation));
                    break;
                case BinaryTypeEnum.String:
                case BinaryTypeEnum.Object: 
                case BinaryTypeEnum.StringArray:
                case BinaryTypeEnum.ObjectArray: 
                    break; 
                case BinaryTypeEnum.ObjectUrt:
                    Contract.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null"); 
                    sout.WriteString(typeInformation.ToString());
                    break;
                case BinaryTypeEnum.ObjectUser:
                    Contract.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null"); 
                    sout.WriteString(typeInformation.ToString());
                    sout.WriteInt32(assemId); 
                    break; 
                default:
                    throw new SerializationException(Environment.GetResourceString("Serialization_TypeWrite",((Enum)binaryTypeEnum).ToString())); 
            }
            SerTrace.Log( "BinaryConverter", "WriteTypeInfo Exit");
        }
 internal static void WriteWithCode(Type type, Object value, __BinaryWriter sout)
 {
     if ((object)type == null)
         sout.WriteByte((Byte)InternalPrimitiveTypeE.Null); 
     else if (Object.ReferenceEquals(type, Converter.typeofString))
         WriteStringWithCode((String)value, sout); 
     else 
     {
         InternalPrimitiveTypeE code = Converter.ToCode(type); 
         sout.WriteByte((Byte)code);
         sout.WriteValue(code, value);
     }
 } 
        public  void Write(__BinaryWriter sout)
        {

            sout.WriteByte((Byte)binaryHeaderEnum); 
            sout.WriteInt32(objectId);
            sout.WriteString(name); 
            sout.WriteInt32(numMembers); 
            for (int i=0; i<numMembers; i++)
                sout.WriteString(memberNames[i]); 
            if (assemId > 0)
                sout.WriteInt32(assemId);
        }
 public  void Write(__BinaryWriter sout)
 { 
     sout.WriteByte((Byte)BinaryHeaderEnum.Object);
     sout.WriteInt32(objectId); 
     sout.WriteInt32(mapId); 
 }
 public  void Write(__BinaryWriter sout) 
 {
     sout.WriteByte((Byte)BinaryHeaderEnum.CrossAppDomainMap);
     sout.WriteInt32(crossAppDomainArrayIndex);
 } 
 public  void Write(__BinaryWriter sout)
 { 
     sout.WriteByte((Byte)BinaryHeaderEnum.MemberPrimitiveTyped);
     sout.WriteByte((Byte)primitiveTypeEnum); //pdj 
     sout.WriteValue(primitiveTypeEnum, value); 
 }
 public  void Write(__BinaryWriter sout) 
 {
     sout.WriteByte((Byte)BinaryHeaderEnum.CrossAppDomainString); 
     sout.WriteInt32(objectId); 
     sout.WriteInt32(value);
 } 
 public  void Write(__BinaryWriter sout) 
 {
     sout.WriteByte((Byte)BinaryHeaderEnum.ObjectString); 
     sout.WriteInt32(objectId);
     sout.WriteString(value);
 }
        public void Write(__BinaryWriter sout)
        {
            sout.WriteByte((Byte)BinaryHeaderEnum.MethodReturn); 
            sout.WriteInt32((Int32)messageEnum);
 
            if (IOUtil.FlagTest(messageEnum, MessageEnum.ReturnValueInline)) 
            {
                IOUtil.WriteWithCode(returnType, returnValue, sout); 
            }

            if (IOUtil.FlagTest(messageEnum, MessageEnum.ContextInline))
                IOUtil.WriteStringWithCode((String)callContext, sout); 

            if (IOUtil.FlagTest(messageEnum, MessageEnum.ArgsInline)) 
            { 
                sout.WriteInt32(args.Length);
                for (int i=0; i<args.Length; i++) 
                {
                    IOUtil.WriteWithCode(argTypes[i], args[i], sout);
                }
            } 
        }
 public void Write(__BinaryWriter sout) 
 {
     sout.WriteByte((Byte)BinaryHeaderEnum.Assembly);
     sout.WriteInt32(assemId);
     sout.WriteString(assemblyString); 
 }
        public  void Write(__BinaryWriter sout)
        { 
            sout.WriteByte((Byte)binaryHeaderEnum);
            sout.WriteInt32(objectId); 
            sout.WriteString(name); 
            sout.WriteInt32(numMembers);
            for (int i=0; i<numMembers; i++) 
                sout.WriteString(memberNames[i]);
            for (int i=0; i<numMembers; i++)
                sout.WriteByte((Byte)binaryTypeEnumA[i]);
            for (int i=0; i<numMembers; i++) 
                //if (binaryTypeEnumA[i] != BinaryTypeEnum.ObjectUrt && binaryTypeEnumA[i] != BinaryTypeEnum.ObjectUser)
                    BinaryConverter.WriteTypeInfo(binaryTypeEnumA[i], typeInformationA[i], memberAssemIds[i], sout); 
 
            if (assemId > 0)
                sout.WriteInt32(assemId); 

        }
 public void Write(__BinaryWriter sout) 
 { 
     sout.WriteByte((Byte)BinaryHeaderEnum.CrossAppDomainAssembly);
     sout.WriteInt32(assemId); 
     sout.WriteInt32(assemblyIndex);
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, bool fCheck)
        {
            if (graph == null)
                throw new ArgumentNullException("graph", Environment.GetResourceString("ArgumentNull_Graph"));

            if (serWriter == null)
                throw new ArgumentNullException("serWriter", Environment.GetResourceString("ArgumentNull_WithParamName", "serWriter"));
            Contract.EndContractBlock();

            SerTrace.Log(this, "Serialize Entry 2 ", graph, ((headers == null) ? " no headers " : "headers "));

            if (fCheck)
            {
                CodeAccessPermission.Demand(PermissionType.SecuritySerialization);          
            }

            this.serWriter = serWriter;
            this.headers = inHeaders;

            SerTrace.Log( this, "Serialize New SerializedTypeTable");
            serWriter.WriteBegin();
            long headerId = 0;
            Object obj;
            long objectId;
            bool isNew;
            bool bMethodCall = false;
            bool bMethodReturn = false;

#if FEATURE_REMOTING        
            // Special case IMethodCallMessage and IMethodReturnMessage for performance
            IMethodCallMessage mess = graph as IMethodCallMessage;
            if (mess != null)
            {
                bMethodCall = true;
                graph = WriteMethodCall(mess);
            }
            else
            {
                IMethodReturnMessage mr = graph as IMethodReturnMessage;
                if (mr != null)
                {
                    bMethodReturn = true;
                    graph = WriteMethodReturn(mr);
                }
            }
#endif // FEATURE_REMOTING        

            if (graph == null)
            {
                WriteSerializedStreamHeader(topId, headerId);

                if (bMethodCall)
                    serWriter.WriteMethodCall();
                else if (bMethodReturn)
                    serWriter.WriteMethodReturn();

                serWriter.WriteSerializationHeaderEnd();
                serWriter.WriteEnd();
                return;
            }

            // allocations if methodCall or methodResponse and no graph
            m_idGenerator = new ObjectIDGenerator();
            m_objectQueue = new Queue();
            m_formatterConverter = new FormatterConverter();
            serObjectInfoInit = new SerObjectInfoInit();        

            topId = InternalGetId(graph, false, null, out isNew);


            if (headers != null)
                headerId = InternalGetId(headers, false, null, out isNew);
            else
                headerId = -1;

            WriteSerializedStreamHeader(topId, headerId);


            if (bMethodCall)
                serWriter.WriteMethodCall();
            else if (bMethodReturn)
                serWriter.WriteMethodReturn();


            SerTrace.Log( this, "Serialize Schedule 0");
            // Write out SerializedStream header
            if ((headers != null) && (headers.Length > 0))
                m_objectQueue.Enqueue(headers);                 

            if (graph != null)
                m_objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId))!=null)
            {
                SerTrace.Log( this, "Serialize GetNext ",obj);
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo. 
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    SerTrace.Log( this, "Serialize GetNext recognizes WriteObjectInfo");
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo = WriteObjectInfo.Serialize(obj, m_surrogates, m_context, serObjectInfoInit, m_formatterConverter, this, m_binder);
                    objectInfo.assemId = GetAssemblyId(objectInfo);
                }


                objectInfo.objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            m_objectManager.RaiseOnSerializedEvent();
            
            SerTrace.Log( this, "Serialize Exit ");
        }
        internal void Write(__BinaryWriter sout)
        { 
            sout.WriteByte((Byte)BinaryHeaderEnum.MethodCall); 
            sout.WriteInt32((Int32)messageEnum);
            //IOUtil.WriteStringWithCode(uri, sout); 
            IOUtil.WriteStringWithCode(methodName, sout);
            IOUtil.WriteStringWithCode(typeName, sout);
            if (IOUtil.FlagTest(messageEnum, MessageEnum.ContextInline))
                IOUtil.WriteStringWithCode((String)callContext, sout); 

            if (IOUtil.FlagTest(messageEnum, MessageEnum.ArgsInline)) 
            { 
                sout.WriteInt32(args.Length);
                for (int i=0; i<args.Length; i++) 
                {
                    IOUtil.WriteWithCode(argTypes[i], args[i], sout);
                }
 
            }
        } 
 internal void Serialize(Stream serializationStream, object graph, Header[] headers, bool fCheck)
 {
     if (serializationStream == null)
     {
         throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { serializationStream }));
     }
     InternalFE formatterEnums = new InternalFE {
         FEtypeFormat = this.m_typeFormat,
         FEserializerTypeEnum = InternalSerializerTypeE.Binary,
         FEassemblyFormat = this.m_assemblyFormat
     };
     ObjectWriter objectWriter = new ObjectWriter(this.m_surrogates, this.m_context, formatterEnums, this.m_binder);
     __BinaryWriter serWriter = new __BinaryWriter(serializationStream, objectWriter, this.m_typeFormat);
     objectWriter.Serialize(graph, headers, serWriter, fCheck);
     this.m_crossAppDomainArray = objectWriter.crossAppDomainArray;
 }
        public  void Write(__BinaryWriter sout) 
        {
            SerTrace.Log( this, "Write"); 
            switch (binaryHeaderEnum) 
            {
                case BinaryHeaderEnum.ArraySinglePrimitive: 
                    sout.WriteByte((Byte)binaryHeaderEnum);
                    sout.WriteInt32(objectId);
                    sout.WriteInt32(lengthA[0]);
                    sout.WriteByte((Byte)((InternalPrimitiveTypeE)typeInformation)); 
                    break;
                case BinaryHeaderEnum.ArraySingleString: 
                    sout.WriteByte((Byte)binaryHeaderEnum); 
                    sout.WriteInt32(objectId);
                    sout.WriteInt32(lengthA[0]); 
                    break;
                case BinaryHeaderEnum.ArraySingleObject:
                    sout.WriteByte((Byte)binaryHeaderEnum);
                    sout.WriteInt32(objectId); 
                    sout.WriteInt32(lengthA[0]);
                    break; 
                default: 
                    sout.WriteByte((Byte)binaryHeaderEnum);
                    sout.WriteInt32(objectId); 
                    sout.WriteByte((Byte)binaryArrayTypeEnum);
                    sout.WriteInt32(rank);
                    for (int i=0; i<rank; i++)
                        sout.WriteInt32(lengthA[i]); 
                    if ((binaryArrayTypeEnum == BinaryArrayTypeEnum.SingleOffset) ||
                        (binaryArrayTypeEnum == BinaryArrayTypeEnum.JaggedOffset) || 
                        (binaryArrayTypeEnum == BinaryArrayTypeEnum.RectangularOffset)) 
                    {
                        for (int i=0; i<rank; i++) 
                            sout.WriteInt32(lowerBoundA[i]);
                    }
                    sout.WriteByte((Byte)binaryTypeEnum);
                    BinaryConverter.WriteTypeInfo(binaryTypeEnum, typeInformation, assemId, sout); 
                    break;
            } 
 
        }
 internal static void WriteStringWithCode(String value, __BinaryWriter sout)
 { 
     if (value == null)
         sout.WriteByte((Byte)InternalPrimitiveTypeE.Null);
     else
     { 
         sout.WriteByte((Byte)InternalPrimitiveTypeE.String);
         sout.WriteString(value); 
     } 
 }
        // Commences the process of serializing the entire graph.  All of the data (in the appropriate format
        // is emitted onto the stream).
        internal void Serialize(Stream serializationStream, Object graph, Header[] headers, bool fCheck)
        {
            if (serializationStream==null)
            {
                throw new ArgumentNullException("serializationStream", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentNull_WithParamName"),serializationStream));             
            }
            SerTrace.Log(this, "Serialize Entry");

            InternalFE formatterEnums = new InternalFE();
            formatterEnums.FEtypeFormat = m_typeFormat;
            formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
            formatterEnums.FEassemblyFormat = m_assemblyFormat;    

            ObjectWriter sow = new ObjectWriter(m_surrogates, m_context, formatterEnums);
            __BinaryWriter binaryWriter = new __BinaryWriter(serializationStream, sow, m_typeFormat); 
            sow.Serialize(graph, headers, binaryWriter, fCheck);
            m_crossAppDomainArray = sow.crossAppDomainArray;
        }
 public  void Write(__BinaryWriter sout)
 { 
     sout.WriteValue(typeInformation, value); 
 }