BinaryCommonClasses.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Runtime / Serialization / Formatters / Binary / BinaryCommonClasses.cs / 2 / BinaryCommonClasses.cs

                            // ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
/*============================================================
 ** 
 ** Class: CommonBinaryClasses 
 **
 ** 
 ** Purpose: utility classes
 **
 **
 ===========================================================*/ 

 
namespace System.Runtime.Serialization.Formatters.Binary{ 

    using System; 
    using System.IO;
    using System.Runtime.Serialization.Formatters;
    using System.Text;
    using System.Collections; 
    using System.Reflection;
    using System.Diagnostics; 
    using System.Runtime.Remoting.Messaging; 
    using System.Globalization;
 
    // Routines to convert between the runtime type and the type as it appears on the wire
    internal static class BinaryConverter
    {
 
        // From the type create the BinaryTypeEnum and typeInformation which describes the type on the wire
 
        internal static BinaryTypeEnum GetBinaryTypeInfo(Type type, WriteObjectInfo objectInfo, String typeName, ObjectWriter objectWriter, out Object typeInformation, out int assemId) 
        {
            SerTrace.Log("BinaryConverter", "GetBinaryTypeInfo Entry type ",type,", typeName ",typeName," objectInfo "+objectInfo); 
            BinaryTypeEnum binaryTypeEnum;

            assemId = 0;
            typeInformation = null; 

            if (type == Converter.typeofString) 
                binaryTypeEnum = BinaryTypeEnum.String; 
            else if (((objectInfo == null) || ((objectInfo != null) && !objectInfo.isSi))
                     && (type == Converter.typeofObject)) 
            {
                // If objectInfo.Si then can be a surrogate which will change the type
                binaryTypeEnum = BinaryTypeEnum.Object;
            } 
            else if (type == Converter.typeofStringArray)
                binaryTypeEnum = BinaryTypeEnum.StringArray; 
            else if (type == Converter.typeofObjectArray) 
                binaryTypeEnum = BinaryTypeEnum.ObjectArray;
            else if (Converter.IsPrimitiveArray(type, out typeInformation)) 
                binaryTypeEnum = BinaryTypeEnum.PrimitiveArray;
            else
            {
                InternalPrimitiveTypeE primitiveTypeEnum = objectWriter.ToCode(type); 
                switch (primitiveTypeEnum)
                { 
                    case InternalPrimitiveTypeE.Invalid: 
                        String assembly = null;
                        if (objectInfo == null) 
                        {
                            assembly = type.Assembly.FullName;
                            typeInformation = type.FullName;
                        } 
                        else
                        { 
                            assembly = objectInfo.GetAssemblyString(); 
                            typeInformation = objectInfo.GetTypeFullName();
                        } 

                        if (assembly.Equals(Converter.urtAssemblyString))
                        {
                            binaryTypeEnum = BinaryTypeEnum.ObjectUrt; 
                            assemId = 0;
                        } 
                        else 
                        {
                            binaryTypeEnum = BinaryTypeEnum.ObjectUser; 
                            BCLDebug.Assert(objectInfo!=null, "[BinaryConverter.GetBinaryTypeInfo]objectInfo null for user object");
                            assemId = (int)objectInfo.assemId;
                            if (assemId == 0)
                                throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_AssemblyId"),typeInformation)); 
                        }
                        break; 
                    default: 
                        binaryTypeEnum = BinaryTypeEnum.Primitive;
                        typeInformation = primitiveTypeEnum; 
                        break;
                }
            }
 
            SerTrace.Log( "BinaryConverter", "GetBinaryTypeInfo Exit ",((Enum)binaryTypeEnum).ToString(),", typeInformation ",typeInformation," assemId ",assemId);
            return binaryTypeEnum; 
        } 

 
        // Used for non Si types when Parsing
        internal static BinaryTypeEnum GetParserBinaryTypeInfo(Type type, out Object typeInformation)
        {
            SerTrace.Log("BinaryConverter", "GetParserBinaryTypeInfo Entry type ",type); 
            BinaryTypeEnum binaryTypeEnum;
            typeInformation = null; 
 
            if (type == Converter.typeofString)
                binaryTypeEnum = BinaryTypeEnum.String; 
            else if (type == Converter.typeofObject)
                binaryTypeEnum = BinaryTypeEnum.Object;
            else if (type == Converter.typeofObjectArray)
                binaryTypeEnum = BinaryTypeEnum.ObjectArray; 
            else if (type == Converter.typeofStringArray)
                binaryTypeEnum = BinaryTypeEnum.StringArray; 
            else if (Converter.IsPrimitiveArray(type, out typeInformation)) 
                binaryTypeEnum = BinaryTypeEnum.PrimitiveArray;
            else 
            {
                InternalPrimitiveTypeE primitiveTypeEnum = Converter.ToCode(type);
                switch (primitiveTypeEnum)
                { 
                    case InternalPrimitiveTypeE.Invalid:
                        if (Assembly.GetAssembly(type) == Converter.urtAssembly) 
                            binaryTypeEnum = BinaryTypeEnum.ObjectUrt; 
                        else
                            binaryTypeEnum = BinaryTypeEnum.ObjectUser; 

                        typeInformation = type.FullName;
                        break;
                    default: 
                        binaryTypeEnum = BinaryTypeEnum.Primitive;
                        typeInformation = primitiveTypeEnum; 
                        break; 
                }
            } 

            SerTrace.Log( "BinaryConverter", "GetParserBinaryTypeInfo Exit ",((Enum)binaryTypeEnum).ToString(),", typeInformation ",typeInformation);
            return binaryTypeEnum;
        } 

        // 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:
                    BCLDebug.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:
                    BCLDebug.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null"); 
                    sout.WriteString(typeInformation.ToString()); 
                    break;
                case BinaryTypeEnum.ObjectUser: 
                    BCLDebug.Assert(typeInformation!=null, "[BinaryConverter.WriteTypeInfo]typeInformation!=null");
                    sout.WriteString(typeInformation.ToString());
                    sout.WriteInt32(assemId);
                    break; 
                default:
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_TypeWrite"),((Enum)binaryTypeEnum).ToString())); 
            } 
            SerTrace.Log( "BinaryConverter", "WriteTypeInfo Exit");
        } 

        // Reads the type information from the wire
        internal static Object ReadTypeInfo(BinaryTypeEnum binaryTypeEnum, __BinaryParser input, out int assemId)
        { 
            SerTrace.Log( "BinaryConverter", "ReadTypeInfo Entry  ",((Enum)binaryTypeEnum).ToString());
            Object var = null; 
            int readAssemId = 0; 

            switch (binaryTypeEnum) 
            {
                case BinaryTypeEnum.Primitive:
                case BinaryTypeEnum.PrimitiveArray:
                    var = (InternalPrimitiveTypeE)input.ReadByte(); 
                    break;
                case BinaryTypeEnum.String: 
                case BinaryTypeEnum.Object: 
                case BinaryTypeEnum.StringArray:
                case BinaryTypeEnum.ObjectArray: 
                    break;
                case BinaryTypeEnum.ObjectUrt:
                    var = input.ReadString();
                    break; 
                case BinaryTypeEnum.ObjectUser:
                    var = input.ReadString(); 
                    readAssemId = input.ReadInt32(); 
                    break;
                default: 
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_TypeRead"),((Enum)binaryTypeEnum).ToString()));
            }
            SerTrace.Log( "BinaryConverter", "ReadTypeInfo Exit  ",var," assemId ",readAssemId);
            assemId = readAssemId; 
            return var;
        } 
 
        // Given the wire type information, returns the actual type and additional information
        internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, 
                                          Object typeInformation,
                                          ObjectReader objectReader,
                                          BinaryAssemblyInfo assemblyInfo,
                                          out InternalPrimitiveTypeE primitiveTypeEnum, 
                                          out String typeString,
                                          out Type type, 
                                          out bool isVariant) 
        {
            SerTrace.Log( "BinaryConverter", "TypeFromInfo Entry  ",((Enum)binaryTypeEnum).ToString()); 

            isVariant = false;
            primitiveTypeEnum = InternalPrimitiveTypeE.Invalid;
            typeString = null; 
            type = null;
 
            switch (binaryTypeEnum) 
            {
                case BinaryTypeEnum.Primitive: 
                    primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation;
                    typeString = Converter.ToComType(primitiveTypeEnum);
                    type = Converter.ToType(primitiveTypeEnum);
                    break; 
                case BinaryTypeEnum.String:
                    //typeString = "System.String"; 
                    type = Converter.typeofString; 
                    break;
                case BinaryTypeEnum.Object: 
                    //typeString = "System.Object";
                    type = Converter.typeofObject;
                    isVariant = true;
                    break; 
                case BinaryTypeEnum.ObjectArray:
                    //typeString = "System.Object[]"; 
                    type = Converter.typeofObjectArray; 
                    break;
                case BinaryTypeEnum.StringArray: 
                    //typeString = "System.String[]";
                    type = Converter.typeofStringArray;
                    break;
                case BinaryTypeEnum.PrimitiveArray: 
                    primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation;
                    type = Converter.ToArrayType(primitiveTypeEnum); 
                    break; 
                case BinaryTypeEnum.ObjectUser:
                case BinaryTypeEnum.ObjectUrt: 
                    if (typeInformation != null)
                    {
                        typeString = typeInformation.ToString();
                        type = objectReader.GetType(assemblyInfo, typeString); 
                        // Temporary for backward compatibility
                        if (type == Converter.typeofObject) 
                            isVariant = true; 
                    }
                    break; 
                default:
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_TypeRead"),((Enum)binaryTypeEnum).ToString()));
            }
 
#if _DEBUG
                SerTrace.Log( "BinaryConverter", "TypeFromInfo Exit  " 
                          ,((Enum)primitiveTypeEnum).ToString(),",typeString ",Util.PString(typeString) 
                          ,", type ",Util.PString(type),", isVariant ",isVariant);
#endif 

        }

#if _DEBUG 
         // Used to write type type on the record dump
        internal static String TypeInfoTraceString(Object typeInformation) 
        { 
            String traceString = null;
            if (typeInformation == null) 
                traceString = "(Null)";
            else if (typeInformation is String)
                traceString = "(UTF)";
            else 
                traceString = "(Byte)";
            return traceString; 
        } 
#endif
 
        internal static bool IsTypePrimitive(Type type)
        {
            InternalPrimitiveTypeE code = Converter.ToCode(type);
            return code != InternalPrimitiveTypeE.Invalid; 
        }
    } 
 
    internal static class IOUtil
    { 
        internal static bool FlagTest(MessageEnum flag, MessageEnum target)
        {
            if ((flag & target) == target)
                return true; 
            else
                return false; 
        } 

        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); 
            }
        } 

        internal static void WriteWithCode(Type type, Object value, __BinaryWriter sout)
        {
            if (type == null) 
                sout.WriteByte((Byte)InternalPrimitiveTypeE.Null);
            else if (type == Converter.typeofString) 
                WriteStringWithCode((String)value, sout); 
            else
            { 
                InternalPrimitiveTypeE code = Converter.ToCode(type);
                sout.WriteByte((Byte)code);
                sout.WriteValue(code, value);
            } 
        }
 
        internal static Object ReadWithCode(__BinaryParser input) 
        {
             InternalPrimitiveTypeE code = (InternalPrimitiveTypeE)input.ReadByte(); 
             if (code == InternalPrimitiveTypeE.Null)
                 return null;
             else if (code == InternalPrimitiveTypeE.String)
                 return input.ReadString(); 
             else
                 return input.ReadValue(code); 
        } 

        internal static Object[] ReadArgs(__BinaryParser input) 
        {
            int length = input.ReadInt32();
            Object[] args = new Object[length];
            for (int i=0; i binaryFormatterMajorVersion)
                throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_InvalidFormat"), BitConverter.ToString(headerBytes)));
 
            // binaryHeaderEnum has already been read
            binaryHeaderEnum = (BinaryHeaderEnum)headerBytes[0]; 
            topId = GetInt32(headerBytes, 1); 
            headerId = GetInt32(headerBytes, 5);
            minorVersion = GetInt32(headerBytes, 13); 
        }

        public  void Dump()
        { 
            DumpInternal();
        } 
 

        [Conditional("_LOGGING")] 
        private void DumpInternal()
        {
            if (BCLDebug.CheckEnabled("BINARY"))
            { 
                BCLDebug.Trace("BINARY", "*****SerializationHeaderRecord*****");
                BinaryUtil.NVTraceI("binaryHeaderEnum (Byte)", ((Enum)binaryHeaderEnum).ToString()); 
                BinaryUtil.NVTraceI("topId (Int32)", topId); 
                BinaryUtil.NVTraceI("headerId (Int32)", headerId);
                BinaryUtil.NVTraceI("majorVersion (Int32)", majorVersion); 
                BinaryUtil.NVTraceI("minorVersion (Int32)", minorVersion);
                BCLDebug.Trace("BINARY","***********************************");
            }
        } 
    }
 
 
    internal sealed class BinaryAssembly : IStreamable
    { 
        internal Int32 assemId;
        internal String assemblyString;

        internal BinaryAssembly() 
        {
        } 
 

        internal void Set(Int32 assemId, String assemblyString) 
        {
            SerTrace.Log( this, "BinaryAssembly Set ",assemId," ",assemblyString);
            this.assemId = assemId;
            this.assemblyString = assemblyString; 
        }
 
 
        public void Write(__BinaryWriter sout)
        { 
            sout.WriteByte((Byte)BinaryHeaderEnum.Assembly);
            sout.WriteInt32(assemId);
            sout.WriteString(assemblyString);
        } 

        public void Read(__BinaryParser input) 
        { 
            assemId = input.ReadInt32();
            assemblyString = input.ReadString(); 
        }

        public void Dump()
        { 
            DumpInternal();
        } 
 
        [Conditional("_LOGGING")]
        private void DumpInternal() 
        {
            if (BCLDebug.CheckEnabled("BINARY"))
            {
                BCLDebug.Trace("BINARY","*****BinaryAssembly*****"); 
                BinaryUtil.NVTraceI("binaryHeaderEnum (Byte)", "Assembly");
                BinaryUtil.NVTraceI("assemId (Int32)", assemId); 
                BinaryUtil.NVTraceI("Assembly (UTF)", assemblyString); 
                BCLDebug.Trace("BINARY","****************************");
            } 
        }
    }

    internal sealed class BinaryCrossAppDomainAssembly : IStreamable 
    {
        internal Int32 assemId; 
        internal Int32 assemblyIndex; 

        internal BinaryCrossAppDomainAssembly() 
        {
        }

        public void Write(__BinaryWriter sout) 
        {
            sout.WriteByte((Byte)BinaryHeaderEnum.CrossAppDomainAssembly); 
            sout.WriteInt32(assemId); 
            sout.WriteInt32(assemblyIndex);
        } 

        public void Read(__BinaryParser input)
        {
            assemId = input.ReadInt32(); 
            assemblyIndex = input.ReadInt32();
        } 
 
        public void Dump()
        { 
            DumpInternal();
        }

        [Conditional("_LOGGING")] 
        private void DumpInternal()
        { 
            if (BCLDebug.CheckEnabled("BINARY")) 
            {
                BCLDebug.Trace("BINARY","*****BinaryCrossAppDomainAssembly*****"); 
                BinaryUtil.NVTraceI("binaryHeaderEnum (Byte)", "CrossAppDomainAssembly");
                BinaryUtil.NVTraceI("assemId (Int32)", assemId);
                BinaryUtil.NVTraceI("assemblyIndex (Int32)", assemblyIndex);
                BCLDebug.Trace("BINARY","****************************"); 
            }
        } 
    } 

 
    internal sealed class BinaryObject : IStreamable
    {
        internal Int32 objectId;
        internal Int32 mapId; 

        internal BinaryObject() 
        { 
        }
 
        internal  void Set(Int32 objectId, Int32 mapId)
        {
            SerTrace.Log( this, "BinaryObject Set ",objectId," ",mapId);
            this.objectId = objectId; 
            this.mapId = mapId;
        } 
 

        public  void Write(__BinaryWriter sout) 
        {
            sout.WriteByte((Byte)BinaryHeaderEnum.Object);
            sout.WriteInt32(objectId);
            sout.WriteInt32(mapId); 
        }
 
        public  void Read(__BinaryParser input) 
        {
            objectId = input.ReadInt32(); 
            mapId = input.ReadInt32();
        }

        public  void Dump() 
        {
            DumpInternal(); 
        } 

        [Conditional("_LOGGING")] 
        private void DumpInternal()
        {
            if (BCLDebug.CheckEnabled("BINARY"))
            { 
                BCLDebug.Trace("BINARY","*****BinaryObject*****");
                BinaryUtil.NVTraceI("binaryHeaderEnum (Byte)", "Object"); 
                BinaryUtil.NVTraceI("objectId (Int32)", objectId); 
                BinaryUtil.NVTraceI("mapId (Int32)", mapId);
                BCLDebug.Trace("BINARY","****************************"); 
            }
        }
    }
 
    internal sealed class BinaryMethodCall
    { 
        String uri; 
        String methodName;
        String typeName; 
        Type[] instArgs;
        Object[] args;
        Object methodSignature;
        Object callContext; 
        String scallContext;
        Object properties; 
        Type[] argTypes; 
        bool bArgsPrimitive = true;
        MessageEnum messageEnum; 
        Object[] callA;

        // If the argument list contains only primitive or strings it is written out as part of the header
        // if not the args are written out as a separate array 
        internal Object[] WriteArray(String uri, String methodName, String typeName, Type[] instArgs, Object[] args, Object methodSignature, Object callContext, Object[] properties)
        { 
            this.uri = uri; 
            this.methodName = methodName;
            this.typeName = typeName; 
            this.instArgs = instArgs;
            this.args = args;
            this.methodSignature = methodSignature;
            this.callContext = callContext; 
            this.properties = properties;
 
            int arraySize = 0; 
            if (args == null || args.Length == 0)
                messageEnum = MessageEnum.NoArgs; 
            else
            {
                argTypes = new Type[args.Length];
                // Check if args are all string or primitives 
                bArgsPrimitive = true;
                for (int i =0; i 0)
            { 
                int arrayPosition = 0;
                callA = new Object[arraySize]; 
                if (IOUtil.FlagTest(messageEnum, MessageEnum.ArgsInArray)) 
                    callA[arrayPosition++] = args;
 
                if (IOUtil.FlagTest(messageEnum, MessageEnum.GenericMethod))
                    callA[arrayPosition++] = instArgs;

                if (IOUtil.FlagTest(messageEnum, MessageEnum.MethodSignatureInArray)) 
                    callA[arrayPosition++] = methodSignature;
 
                if (IOUtil.FlagTest(messageEnum, MessageEnum.ContextInArray)) 
                    callA[arrayPosition++] = callContext;
 
                if (IOUtil.FlagTest(messageEnum, MessageEnum.PropertyInArray))
                    callA[arrayPosition] = properties;

                 return callA; 
            }
            else 
                return null; 
        }
 
        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 0)
            { 
                int arrayPosition = 0;
                callA = new Object[arraySize];
                if (IOUtil.FlagTest(messageEnum, MessageEnum.ArgsInArray))
                    callA[arrayPosition++] = args; 

                if (IOUtil.FlagTest(messageEnum, MessageEnum.ReturnValueInArray)) 
                    callA[arrayPosition++] = returnValue; 

                if (IOUtil.FlagTest(messageEnum, MessageEnum.ExceptionInArray)) 
                    callA[arrayPosition++] = exception;

                if (IOUtil.FlagTest(messageEnum, MessageEnum.ContextInArray))
                    callA[arrayPosition++] = callContext; 

                if (IOUtil.FlagTest(messageEnum, MessageEnum.PropertyInArray)) 
                    callA[arrayPosition] = properties; 

                 return callA; 
            }
            else
                return null;
        } 

 
        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 0) 
                binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMapAssemId;
            else
                binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMap;
 
        }
 
        public  void Write(__BinaryWriter sout) 
        {
 
            sout.WriteByte((Byte)binaryHeaderEnum);
            sout.WriteInt32(objectId);
            sout.WriteString(name);
            sout.WriteInt32(numMembers); 
            for (int i=0; i 0) 
                sout.WriteInt32(assemId);
        } 

        public  void Read(__BinaryParser input)
        {
            objectId = input.ReadInt32(); 
            name = input.ReadString();
            numMembers = input.ReadInt32(); 
            memberNames = new String[numMembers]; 
            for (int i=0; i 0)
                binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMapTypedAssemId;
            else
                binaryHeaderEnum = BinaryHeaderEnum.ObjectWithMapTyped; 
        }
 
 
        public  void Write(__BinaryWriter sout)
        { 
            sout.WriteByte((Byte)binaryHeaderEnum);
            sout.WriteInt32(objectId);
            sout.WriteString(name);
            sout.WriteInt32(numMembers); 
            for (int i=0; i 0) 
                sout.WriteInt32(assemId);
 
        } 

        public  void Read(__BinaryParser input) 
        {
            // binaryHeaderEnum has already been read
            objectId = input.ReadInt32();
            name = input.ReadString(); 
            numMembers = input.ReadInt32();
            memberNames = new String[numMembers]; 
            binaryTypeEnumA = new BinaryTypeEnum[numMembers]; 
            typeInformationA = new Object[numMembers];
            memberAssemIds = new Int32[numMembers]; 
            for (int i=0; i 1000) 
                    opRecordIdCount = 1; 
            }
        } 

        internal void Init()
        {
            isInitial = false; 
            count = 0;
            expectedType = BinaryTypeEnum.ObjectUrt; 
            expectedTypeInformation = null; 

            name = null; 
            objectTypeEnum = InternalObjectTypeE.Empty;
            memberTypeEnum = InternalMemberTypeE.Empty;
            memberValueEnum = InternalMemberValueE.Empty;
            dtType = null; 

            // Array Information 
            numItems = 0; 
            nullCount = 0;
            //binaryTypeEnum 
            typeInformation = null;

            // Member Information
            memberLength = 0; 
            binaryTypeEnumA = null;
            typeInformationA = null; 
            memberNames = null; 
            memberTypes = null;
 
            pr.Init();
        }

        //Array item entry of nulls has a count of nulls represented by that item. The first null has been 
        // incremented by GetNext, the rest of the null counts are incremented here
        internal void ArrayCountIncrement(int value) 
        { 
            count += value;
        } 

        // Specifies what is to parsed next from the wire.
        internal bool GetNext(out BinaryTypeEnum outBinaryTypeEnum, out Object outTypeInformation)
        { 
            //Initialize the out params up here.
            //< 
            outBinaryTypeEnum = BinaryTypeEnum.Primitive; 
            outTypeInformation = null;
 
#if _DEBUG
            SerTrace.Log( this, "GetNext Entry");
            Dump();
#endif 

            if (objectTypeEnum == InternalObjectTypeE.Array) 
            { 
                SerTrace.Log( this, "GetNext Array");
                // Array 
                if (count == numItems)
                    return false;
                else
                { 
                    outBinaryTypeEnum =  binaryTypeEnum;
                    outTypeInformation = typeInformation; 
                    if (count == 0) 
                        isInitial = false;
                    count++; 
                    SerTrace.Log( this, "GetNext Array Exit ",((Enum)outBinaryTypeEnum).ToString()," ",outTypeInformation);
                    return true;
                }
            } 
            else
            { 
                // Member 
                SerTrace.Log( this, "GetNext Member");
                if ((count == memberLength) && (!isInitial)) 
                    return false;
                else
                {
                    outBinaryTypeEnum = binaryTypeEnumA[count]; 
                    outTypeInformation = typeInformationA[count];
                    if (count == 0) 
                        isInitial = false; 
                    name = memberNames[count];
                    if (memberTypes == null) 
                    {
                        SerTrace.Log( this, "GetNext memberTypes = null");
                    }
                    dtType = memberTypes[count]; 
                    count++;
                    SerTrace.Log( this, "GetNext Member Exit ",((Enum)outBinaryTypeEnum).ToString()," ",outTypeInformation," memberName ",name); 
                    return true; 
                }
            } 
        }

#if _DEBUG
// Get a String describing the ObjectProgress Record 
        public  String Trace()
        { 
            return "ObjectProgress "+opRecordId+" name "+Util.PString(name)+" expectedType "+((Enum)expectedType).ToString(); 
        }
 
        // Dump contents of record

        [Conditional("SER_LOGGING")]
        internal  void Dump() 
        {
            try 
            { 
                SerTrace.Log("ObjectProgress Dump ");
                Util.NVTrace("opRecordId", opRecordId); 
                Util.NVTrace("isInitial", isInitial);
                Util.NVTrace("count", count);
                Util.NVTrace("expectedType", ((Enum)expectedType).ToString());
                Util.NVTrace("expectedTypeInformation", expectedTypeInformation); 
                SerTrace.Log("ParseRecord Information");
                Util.NVTrace("name", name); 
                Util.NVTrace("objectTypeEnum",((Enum)objectTypeEnum).ToString()); 
                Util.NVTrace("memberTypeEnum",((Enum)memberTypeEnum).ToString());
                Util.NVTrace("memberValueEnum",((Enum)memberValueEnum).ToString()); 
                if (dtType != null)
                    Util.NVTrace("dtType", dtType.ToString());
                SerTrace.Log("Array Information");
                Util.NVTrace("numItems", numItems); 
                Util.NVTrace("binaryTypeEnum",((Enum)binaryTypeEnum).ToString());
                Util.NVTrace("typeInformation", typeInformation); 
                SerTrace.Log("Member Information"); 
                Util.NVTrace("memberLength", memberLength);
                if (binaryTypeEnumA != null) 
                {
                    for (int i=0; i

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK