Ejemplo n.º 1
0
    private BinaryElement <TKey, TValue> InsertElement(int _index, BinaryElement <TKey, TValue> _b_element)
    {
        BinaryElement <TKey, TValue> result = null;

        InsertInArray(_index, _b_element);

        if (m_elements_count >= m_keys.Length)
        {
            int mid = m_elements_count / 2;
            Pair <TKey, TValue> median = m_keys[mid];
            m_keys[mid] = null;

            BTreeElement <TKey, TValue> right = New();
            right.Init(m_max_elements);

            for (int i = mid + 1, ir = 0; i < m_elements_count; ++i, ++ir)
            {
                right.m_keys[ir] = m_keys[i];
                m_keys[i]        = null;
            }

            for (int i = mid + 1, ir = 0, count = m_elements_count + 1; i < count; ++i, ++ir)
            {
                right.m_neighbors[ir] = m_neighbors[i];
                m_neighbors[i]        = null;
            }

            right.m_elements_count = m_elements_count - mid - 1;
            m_elements_count       = mid;

            result = new BinaryElement <TKey, TValue>(this, right, median);
        }

        return(result);
    }
        public Element ToSimpleBlock()
        {
            BinaryElement blockElement = MatroskaDocTypes.SimpleBlock.GetInstance();

            blockElement.Data = createInnerData();
            return(blockElement);
        }
Ejemplo n.º 3
0
        public void ReadObjectGraph(BinaryElement elem, BinaryReader reader, bool readHeaders, out object result, out Header[] headers)
        {
            headers = null;

            // Reads the objects. The first object in the stream is the
            // root object.
            bool next = ReadNextObject(elem, reader);

            if (next)
            {
                do
                {
                    if (readHeaders && (headers == null))
                    {
                        headers = (Header[])CurrentObject;
                    }
                    else
                    if (_rootObjectID == 0)
                    {
                        _rootObjectID = _lastObjectID;
                    }
                } while (ReadNextObject(reader));
            }

            result = _manager.GetObject(_rootObjectID);
        }
Ejemplo n.º 4
0
        private object NoCheckDeserialize(Stream serializationStream, HeaderHandler handler)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream");
            }
            if (serializationStream.CanSeek && serializationStream.Length == 0L)
            {
                throw new SerializationException("serializationStream supports seeking, but its length is 0");
            }
            BinaryReader binaryReader = new BinaryReader(serializationStream);
            bool         flag;

            this.ReadBinaryHeader(binaryReader, out flag);
            BinaryElement binaryElement = (BinaryElement)binaryReader.Read();

            if (binaryElement == BinaryElement.MethodCall)
            {
                return(MessageFormatter.ReadMethodCall(binaryElement, binaryReader, flag, handler, this));
            }
            if (binaryElement == BinaryElement.MethodResponse)
            {
                return(MessageFormatter.ReadMethodResponse(binaryElement, binaryReader, flag, handler, null, this));
            }
            ObjectReader objectReader = new ObjectReader(this);
            object       result;

            Header[] headers;
            objectReader.ReadObjectGraph(binaryElement, binaryReader, flag, out result, out headers);
            if (handler != null)
            {
                handler(headers);
            }
            return(result);
        }
Ejemplo n.º 5
0
    public BinaryElement <TKey, TValue> Insert(TKey _key, TValue _value)
    {
        int lo   = 0;
        int find = SearchInArray(_key, ref lo);
        BinaryElement <TKey, TValue> insert = null;

        if (find >= 0)
        {
            m_keys[find].Value = _value;
        }
        else if (m_neighbors[lo] != null)
        {
            insert = GetNeighbor(lo).Insert(_key, _value);
        }
        else
        {
            insert = new BinaryElement <TKey, TValue>(m_neighbors[lo], m_neighbors[lo + 1], new Pair <TKey, TValue>(_key, _value));
        }

        if (insert != null)
        {
            return(InsertElement(lo, insert));
        }

        return(null);
    }
Ejemplo n.º 6
0
        public bool ReadNextObject(BinaryReader reader)
        {
            BinaryElement element = (BinaryElement)reader.ReadByte();

            if (element == BinaryElement.End)
            {
                _manager.DoFixups();

                _manager.RaiseDeserializationEvent();
                return(false);
            }

            SerializationInfo info;
            long objectId;

            ReadObject(element, reader, out objectId, out _lastObject, out info);

            if (objectId != 0)
            {
                RegisterObject(objectId, _lastObject, info, 0, null, null);
                _lastObjectID = objectId;
            }

            return(true);
        }
Ejemplo n.º 7
0
    public virtual void Init(int _max_elements, BinaryElement <TKey, TValue> _b_element)
    {
        m_max_elements = _max_elements;

        Init();

        InsertElement(0, _b_element);
    }
Ejemplo n.º 8
0
    public void Insert(TKey _key, TValue _value)
    {
        BinaryElement <TKey, TValue> insert = m_root.Insert(_key, _value);

        if (insert != null)
        {
            m_root = m_root.New();
            m_root.Init(m_max_elements, insert);
        }
    }
Ejemplo n.º 9
0
 public EncryptionAlgorithm()
 {
     Usage     = new NumericElement(2);
     Mode      = new NumericElement(2);
     Algorithm = new NumericElement(13);
     Data      = new BinaryElement("00000000");
     KeyId     = new NumericElement(5);
     IvId      = new NumericElement(1);
     Iv        = null;
 }
        public Element ToBlockGroup()
        {
            MasterElement blockGroupElement = MatroskaDocTypes.BlockGroup.GetInstance();
            BinaryElement blockElement      = MatroskaDocTypes.Block.GetInstance();

            blockElement.Data = createInnerData();
            UnsignedIntegerElement durationElement = MatroskaDocTypes.BlockDuration.GetInstance();

            durationElement.Value = Duration;
            blockGroupElement.AddChildElement(blockElement);
            blockGroupElement.AddChildElement(durationElement);
            return(blockGroupElement);
        }
Ejemplo n.º 11
0
        // shared by Deserialize and UnsafeDeserialize which both involve different security checks
        private object NoCheckDeserialize(Stream serializationStream, HeaderHandler handler)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException("serializationStream");
            }
            if (serializationStream.CanSeek &&
                serializationStream.Length == 0)
            {
                throw new SerializationException("serializationStream supports seeking, but its length is 0");
            }

            BinaryReader reader = new BinaryReader(serializationStream);

            bool hasHeader;

            ReadBinaryHeader(reader, out hasHeader);

            // Messages are read using a special static method, which does not use ObjectReader
            // if it is not needed. This saves time and memory.

            BinaryElement elem = (BinaryElement)reader.Read();

            if (elem == BinaryElement.MethodCall)
            {
                return(MessageFormatter.ReadMethodCall(elem, reader, hasHeader, handler, this));
            }
            else if (elem == BinaryElement.MethodResponse)
            {
                return(MessageFormatter.ReadMethodResponse(elem, reader, hasHeader, handler, null, this));
            }
            else
            {
                ObjectReader serializer = new ObjectReader(this);

                object   result;
                Header[] headers;
                serializer.ReadObjectGraph(elem, reader, hasHeader, out result, out headers);
                if (handler != null)
                {
                    handler(headers);
                }
                return(result);
            }
        }
Ejemplo n.º 12
0
        private void ReadValue(BinaryReader reader, object parentObject, long parentObjectId, SerializationInfo info, Type valueType, string fieldName, MemberInfo memberInfo, int[] indices)
        {
            object obj;

            if (BinaryCommon.IsPrimitive(valueType))
            {
                obj = ObjectReader.ReadPrimitiveTypeValue(reader, valueType);
                this.SetObjectValue(parentObject, fieldName, memberInfo, info, obj, valueType, indices);
                return;
            }
            BinaryElement binaryElement = (BinaryElement)reader.ReadByte();

            if (binaryElement == BinaryElement.ObjectReference)
            {
                long childObjectId = (long)((ulong)reader.ReadUInt32());
                this.RecordFixup(parentObjectId, childObjectId, parentObject, info, fieldName, memberInfo, indices);
                return;
            }
            long num;
            SerializationInfo info2;

            this.ReadObject(binaryElement, reader, out num, out obj, out info2);
            bool flag = false;

            if (num != 0L)
            {
                if (obj.GetType().IsValueType)
                {
                    this.RecordFixup(parentObjectId, num, parentObject, info, fieldName, memberInfo, indices);
                    flag = true;
                }
                if (info == null && !(parentObject is Array))
                {
                    this.RegisterObject(num, obj, info2, parentObjectId, memberInfo, null);
                }
                else
                {
                    this.RegisterObject(num, obj, info2, parentObjectId, null, indices);
                }
            }
            if (!flag)
            {
                this.SetObjectValue(parentObject, fieldName, memberInfo, info, obj, valueType, indices);
            }
        }
        /// <summary>
        /// Adds elements to the seek index. These should be level 1 objects only.
        /// If this object has already been written, you must use the update() method
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="filePosition"></param>
        public void AddIndexedElement(MemoryStream stream, ulong filePosition)
        {
            Utility.LogDebug($"Adding indexed element @ {filePosition - referencePosition}");
            MasterElement seekEntryElement   = MatroskaDocTypes.Seek.GetInstance();
            BinaryElement seekEntryIdElement = MatroskaDocTypes.SeekID.GetInstance();

            seekEntryIdElement.Data = stream;

            UnsignedIntegerElement seekEntryPositionElement = MatroskaDocTypes.SeekPosition.GetInstance();

            seekEntryPositionElement.Value = filePosition - referencePosition;

            seekEntryElement.AddChildElement(seekEntryIdElement);
            seekEntryElement.AddChildElement(seekEntryPositionElement);

            seekHeadElem.AddChildElement(seekEntryElement);
            placeHolderElement.Size = BLOCK_RESEVER_SIZE - seekHeadElem.TotalSize;
        }
Ejemplo n.º 14
0
        private bool ReadNextObject(BinaryElement element, BinaryReader reader)
        {
            if (element == BinaryElement.End)
            {
                this._manager.DoFixups();
                this._manager.RaiseDeserializationEvent();
                return(false);
            }
            long num;
            SerializationInfo info;

            this.ReadObject(element, reader, out num, out this._lastObject, out info);
            if (num != 0L)
            {
                this.RegisterObject(num, this._lastObject, info, 0L, null, null);
                this._lastObjectID = num;
            }
            return(true);
        }
Ejemplo n.º 15
0
        public void ReadObjectGraph(BinaryElement elem, BinaryReader reader, bool readHeaders, out object result, out Header[] headers)
        {
            headers = null;
            bool flag = this.ReadNextObject(elem, reader);

            if (flag)
            {
                do
                {
                    if (readHeaders && headers == null)
                    {
                        headers = (Header[])this.CurrentObject;
                    }
                    else if (this._rootObjectID == 0L)
                    {
                        this._rootObjectID = this._lastObjectID;
                    }
                }while (this.ReadNextObject(reader));
            }
            result = this._manager.GetObject(this._rootObjectID);
        }
Ejemplo n.º 16
0
    private void InsertInArray(int _index, BinaryElement <TKey, TValue> _b_element)
    {
        if (m_elements_count < m_keys.Length)
        {
            ++m_elements_count;
        }

        for (int i = m_elements_count - 1; i > _index; --i)
        {
            m_keys[i] = m_keys[i - 1];
        }

        for (int i = m_elements_count; i > _index; --i)
        {
            m_neighbors[i] = m_neighbors[i - 1];
        }

        m_keys[_index]          = _b_element.Value;
        m_neighbors[_index]     = _b_element.Left;
        m_neighbors[_index + 1] = _b_element.Right;
    }
        internal void ReadTypeMetaData(RSBinaryReader _binaryReader, BinaryElement _binaryElement)
        {
            // Read assembly info
            if (_binaryElement == BinaryElement.ASSEMBLY)
            {
                UInt32   _assemblyID       = _binaryReader.ReadUInt32();
                string   _assemblyFullName = _binaryReader.ReadString();
                Assembly _assembly         = Assembly.Load(_assemblyFullName);

                if (_assembly == null)
                {
                    throw new Exception(string.Format("[RS] Couldnt load assembly with name={0}.", _assemblyFullName));
                }

                // Add assembly info to cache
                m_cachedAssemblies.Add(_assembly, _assemblyID);

                // Read next element
                _binaryElement = _binaryReader.ReadBinaryElement();
            }

            // Read type info
            if (_binaryElement == BinaryElement.TYPE)
            {
                UInt32   _assemblyID   = _binaryReader.ReadUInt32();
                UInt32   _typeID       = _binaryReader.ReadUInt32();
                string   _typeFullName = _binaryReader.ReadString();
                Assembly _assembly     = GetAssembly(_assemblyID);

                if (_assembly == null)
                {
                    throw new Exception(string.Format("[RS] Assembly with ID={0} couldnt be found.", _assemblyID));
                }

                Type _newType = _assembly.GetType(_typeFullName, true);

                // Add type info to cache
                m_cachedObjectTypes.Add(_newType, _typeID);
            }
        }
Ejemplo n.º 18
0
		public static object ReadMethodCall (BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, BinaryFormatter formatter)
		{
			if (elem != BinaryElement.MethodCall) throw new SerializationException("Invalid format. Expected BinaryElement.MethodCall, found " +  elem);

			MethodFlags flags = (MethodFlags) reader.ReadInt32();

			if (((BinaryTypeCode)reader.ReadByte()) != BinaryTypeCode.String) throw new SerializationException ("Invalid format");
			string methodName = reader.ReadString();

			if (((BinaryTypeCode)reader.ReadByte()) != BinaryTypeCode.String) throw new SerializationException ("Invalid format");
			string className = reader.ReadString();

			//bool hasContextInfo = (flags & MethodFlags.IncludesLogicalCallContext) > 0;

			object[] arguments = null;
			object methodSignature = null;
			object callContext = null;
			object[] extraProperties = null;
			Header[] headers = null;
#if NET_2_0
			Type[] genericArguments = null;
#endif

			if ((flags & MethodFlags.PrimitiveArguments) > 0)
			{
				uint count = reader.ReadUInt32();
				arguments = new object[count];
				for (int n=0; n<count; n++)
				{
					Type type = BinaryCommon.GetTypeFromCode (reader.ReadByte());
					arguments[n] = ObjectReader.ReadPrimitiveTypeValue (reader, type);
				}
			}

			if ((flags & MethodFlags.NeedsInfoArrayMask) > 0)
			{
				ObjectReader objectReader = new ObjectReader (formatter);

				object result;
				objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers);
				object[] msgInfo = (object[]) result;

				if ((flags & MethodFlags.ArgumentsInSimpleArray) > 0) {
					arguments = msgInfo;
				}
				else
				{
					int n = 0;
					if ((flags & MethodFlags.ArgumentsInMultiArray) > 0) {
						if (msgInfo.Length > 1) arguments = (object[]) msgInfo[n++];
						else arguments = new object[0];
					}

#if NET_2_0
					if ((flags & MethodFlags.GenericArguments) > 0)
						genericArguments = (Type[]) msgInfo[n++];
#endif

					if ((flags & MethodFlags.IncludesSignature) > 0)
						methodSignature = msgInfo[n++];

					if ((flags & MethodFlags.IncludesLogicalCallContext) > 0) 
						callContext = msgInfo[n++];

					if (n < msgInfo.Length)
						extraProperties = (object[]) msgInfo[n];
				}
			}
			else {
				reader.ReadByte ();	// Reads the stream ender
			}

			if (arguments == null) arguments = new object[0];

			string uri = null;
			if (headerHandler != null)
				uri = headerHandler(headers) as string;

#if NET_2_0
			Header[] methodInfo = new Header[7];
#else
			Header[] methodInfo = new Header[6];
#endif
			methodInfo[0] = new Header("__MethodName", methodName);
			methodInfo[1] = new Header("__MethodSignature", methodSignature);
			methodInfo[2] = new Header("__TypeName", className);
			methodInfo[3] = new Header("__Args", arguments);
			methodInfo[4] = new Header("__CallContext", callContext);
			methodInfo[5] = new Header("__Uri", uri);
#if NET_2_0
			methodInfo[6] = new Header("__GenericArguments", genericArguments);
#endif

			MethodCall call = new MethodCall (methodInfo);

			if (extraProperties != null) {
				foreach (DictionaryEntry entry in extraProperties)
					call.Properties [(string)entry.Key] = entry.Value;
			}

			return call;
		}
Ejemplo n.º 19
0
        public void ReadObjectGraph(BinaryReader reader, bool readHeaders, out object result, out Header[] headers)
        {
            BinaryElement elem = (BinaryElement)reader.ReadByte();

            this.ReadObjectGraph(elem, reader, readHeaders, out result, out headers);
        }
Ejemplo n.º 20
0
        private void ReadObject(BinaryElement element, BinaryReader reader, out long objectId, out object value, out SerializationInfo info)
        {
            switch (element)
            {
            case BinaryElement.RefTypeObject:
                this.ReadRefTypeObjectInstance(reader, out objectId, out value, out info);
                return;

            case BinaryElement.UntypedRuntimeObject:
                this.ReadObjectInstance(reader, true, false, out objectId, out value, out info);
                return;

            case BinaryElement.UntypedExternalObject:
                this.ReadObjectInstance(reader, false, false, out objectId, out value, out info);
                return;

            case BinaryElement.RuntimeObject:
                this.ReadObjectInstance(reader, true, true, out objectId, out value, out info);
                return;

            case BinaryElement.ExternalObject:
                this.ReadObjectInstance(reader, false, true, out objectId, out value, out info);
                return;

            case BinaryElement.String:
                info = null;
                this.ReadStringIntance(reader, out objectId, out value);
                return;

            case BinaryElement.GenericArray:
                info = null;
                this.ReadGenericArray(reader, out objectId, out value);
                return;

            case BinaryElement.BoxedPrimitiveTypeValue:
                value    = this.ReadBoxedPrimitiveTypeValue(reader);
                objectId = 0L;
                info     = null;
                return;

            case BinaryElement.NullValue:
                value    = null;
                objectId = 0L;
                info     = null;
                return;

            case BinaryElement.Assembly:
                this.ReadAssembly(reader);
                this.ReadObject((BinaryElement)reader.ReadByte(), reader, out objectId, out value, out info);
                return;

            case BinaryElement.ArrayFiller8b:
                value    = new ObjectReader.ArrayNullFiller((int)reader.ReadByte());
                objectId = 0L;
                info     = null;
                return;

            case BinaryElement.ArrayFiller32b:
                value    = new ObjectReader.ArrayNullFiller(reader.ReadInt32());
                objectId = 0L;
                info     = null;
                return;

            case BinaryElement.ArrayOfPrimitiveType:
                this.ReadArrayOfPrimitiveType(reader, out objectId, out value);
                info = null;
                return;

            case BinaryElement.ArrayOfObject:
                this.ReadArrayOfObject(reader, out objectId, out value);
                info = null;
                return;

            case BinaryElement.ArrayOfString:
                this.ReadArrayOfString(reader, out objectId, out value);
                info = null;
                return;
            }
            throw new SerializationException("Unexpected binary element: " + (int)element);
        }
        public static object ReadMethodResponse(BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, BinaryFormatter formatter)
        {
            if (elem != BinaryElement.MethodResponse)
            {
                throw new SerializationException("Invalid format. Expected BinaryElement.MethodResponse, found " + elem);
            }

            MethodFlags   flags          = (MethodFlags)reader.ReadByte();
            ReturnTypeTag typeTag        = (ReturnTypeTag)reader.ReadByte();
            bool          hasContextInfo = (flags & MethodFlags.IncludesLogicalCallContext) > 0;

            // FIXME: find a meaning for those 2 bytes
            reader.ReadByte();
            reader.ReadByte();

            object returnValue = null;

            object[]           outArgs     = null;
            LogicalCallContext callContext = null;
            Exception          exception   = null;

            object[] extraProperties = null;
            Header[] headers         = null;

            if ((typeTag & ReturnTypeTag.PrimitiveType) > 0)
            {
                Type type = BinaryCommon.GetTypeFromCode(reader.ReadByte());
                returnValue = ObjectReader.ReadPrimitiveTypeValue(reader, type);
            }

            if ((flags & MethodFlags.PrimitiveArguments) > 0)
            {
                uint count = reader.ReadUInt32();
                outArgs = new object[count];
                for (int n = 0; n < count; n++)
                {
                    Type type = BinaryCommon.GetTypeFromCode(reader.ReadByte());
                    outArgs[n] = ObjectReader.ReadPrimitiveTypeValue(reader, type);
                }
            }

            if (hasContextInfo || (typeTag & ReturnTypeTag.ObjectType) > 0 ||
                (typeTag & ReturnTypeTag.Exception) > 0 ||
                (flags & MethodFlags.ArgumentsInSimpleArray) > 0 ||
                (flags & MethodFlags.ArgumentsInMultiArray) > 0)
            {
                // There objects that need to be deserialized using an ObjectReader

                ObjectReader objectReader = new ObjectReader(formatter);
                object       result;
                objectReader.ReadObjectGraph(reader, hasHeaders, out result, out headers);
                object[] msgInfo = (object[])result;

                if ((typeTag & ReturnTypeTag.Exception) > 0)
                {
                    exception = (Exception)msgInfo[0];
                    if (hasContextInfo)
                    {
                        callContext = (LogicalCallContext)msgInfo[1];
                    }
                }
                else if ((flags & MethodFlags.NoArguments) > 0 || (flags & MethodFlags.PrimitiveArguments) > 0)
                {
                    int n = 0;
                    if ((typeTag & ReturnTypeTag.ObjectType) > 0)
                    {
                        returnValue = msgInfo [n++];
                    }
                    if (hasContextInfo)
                    {
                        callContext = (LogicalCallContext)msgInfo[n++];
                    }
                    if (n < msgInfo.Length)
                    {
                        extraProperties = (object[])msgInfo[n];
                    }
                }
                else if ((flags & MethodFlags.ArgumentsInSimpleArray) > 0)
                {
                    outArgs = msgInfo;
                }
                else
                {
                    int n = 0;
                    outArgs = (object[])msgInfo[n++];
                    if ((typeTag & ReturnTypeTag.ObjectType) > 0)
                    {
                        returnValue = msgInfo[n++];
                    }
                    if (hasContextInfo)
                    {
                        callContext = (LogicalCallContext)msgInfo[n++];
                    }
                    if (n < msgInfo.Length)
                    {
                        extraProperties = (object[])msgInfo[n];
                    }
                }
            }
            else
            {
                reader.ReadByte(); // Reads the stream ender
            }

            if (headerHandler != null)
            {
                headerHandler(headers);
            }

            if (exception != null)
            {
                return(new ReturnMessage(exception, methodCallMessage));
            }
            else
            {
                int           argCount = (outArgs != null) ? outArgs.Length : 0;
                ReturnMessage result   = new ReturnMessage(returnValue, outArgs, argCount, callContext, methodCallMessage);

                if (extraProperties != null)
                {
                    foreach (DictionaryEntry entry in extraProperties)
                    {
                        result.Properties [(string)entry.Key] = entry.Value;
                    }
                }

                return(result);
            }
        }
        public static object ReadMethodResponse(BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, BinaryFormatter formatter)
        {
            BinaryElement elem = (BinaryElement)reader.ReadByte();

            return(ReadMethodResponse(elem, reader, hasHeaders, headerHandler, methodCallMessage, formatter));
        }
        public static object ReadMethodCall(BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, BinaryFormatter formatter)
        {
            if (elem != BinaryElement.MethodCall)
            {
                throw new SerializationException("Invalid format. Expected BinaryElement.MethodCall, found " + elem);
            }

            MethodFlags flags = (MethodFlags)reader.ReadInt32();

            if (((BinaryTypeCode)reader.ReadByte()) != BinaryTypeCode.String)
            {
                throw new SerializationException("Invalid format");
            }
            string methodName = reader.ReadString();

            if (((BinaryTypeCode)reader.ReadByte()) != BinaryTypeCode.String)
            {
                throw new SerializationException("Invalid format");
            }
            string className = reader.ReadString();

            //bool hasContextInfo = (flags & MethodFlags.IncludesLogicalCallContext) > 0;

            object[] arguments       = null;
            object   methodSignature = null;
            object   callContext     = null;

            object[] extraProperties  = null;
            Header[] headers          = null;
            Type[]   genericArguments = null;

            if ((flags & MethodFlags.PrimitiveArguments) > 0)
            {
                uint count = reader.ReadUInt32();
                arguments = new object[count];
                for (int n = 0; n < count; n++)
                {
                    Type type = BinaryCommon.GetTypeFromCode(reader.ReadByte());
                    arguments[n] = ObjectReader.ReadPrimitiveTypeValue(reader, type);
                }
            }

            if ((flags & MethodFlags.NeedsInfoArrayMask) > 0)
            {
                ObjectReader objectReader = new ObjectReader(formatter);

                object result;
                objectReader.ReadObjectGraph(reader, hasHeaders, out result, out headers);
                object[] msgInfo = (object[])result;

                if ((flags & MethodFlags.ArgumentsInSimpleArray) > 0)
                {
                    arguments = msgInfo;
                }
                else
                {
                    int n = 0;
                    if ((flags & MethodFlags.ArgumentsInMultiArray) > 0)
                    {
                        if (msgInfo.Length > 1)
                        {
                            arguments = (object[])msgInfo[n++];
                        }
                        else
                        {
                            arguments = new object[0];
                        }
                    }

                    if ((flags & MethodFlags.GenericArguments) > 0)
                    {
                        genericArguments = (Type[])msgInfo[n++];
                    }

                    if ((flags & MethodFlags.IncludesSignature) > 0)
                    {
                        methodSignature = msgInfo[n++];
                    }

                    if ((flags & MethodFlags.IncludesLogicalCallContext) > 0)
                    {
                        callContext = msgInfo[n++];
                    }

                    if (n < msgInfo.Length)
                    {
                        extraProperties = (object[])msgInfo[n];
                    }
                }
            }
            else
            {
                reader.ReadByte(); // Reads the stream ender
            }

            if (arguments == null)
            {
                arguments = new object[0];
            }

            string uri = null;

            if (headerHandler != null)
            {
                uri = headerHandler(headers) as string;
            }

            Header[] methodInfo = new Header[7];
            methodInfo[0] = new Header("__MethodName", methodName);
            methodInfo[1] = new Header("__MethodSignature", methodSignature);
            methodInfo[2] = new Header("__TypeName", className);
            methodInfo[3] = new Header("__Args", arguments);
            methodInfo[4] = new Header("__CallContext", callContext);
            methodInfo[5] = new Header("__Uri", uri);
            methodInfo[6] = new Header("__GenericArguments", genericArguments);

            MethodCall call = new MethodCall(methodInfo);

            if (extraProperties != null)
            {
                foreach (DictionaryEntry entry in extraProperties)
                {
                    call.Properties [(string)entry.Key] = entry.Value;
                }
            }

            return(call);
        }
Ejemplo n.º 24
0
        public Element ToElement()
        {
            MasterElement trackEntryElement = MatroskaDocTypes.TrackEntry.GetInstance();

            UnsignedIntegerElement trackNumberElement = MatroskaDocTypes.TrackNumber.GetInstance();

            trackNumberElement.Value = (ulong)TrackNumber;

            UnsignedIntegerElement trackUIDElement = MatroskaDocTypes.TrackType.GetInstance();

            trackUIDElement.Value = TrackUID;

            UnsignedIntegerElement trackTypeElement = MatroskaDocTypes.TrackType.GetInstance();

            trackTypeElement.Value = (ulong)TrackType;
            Utility.LogTrace($"Track type set to {TrackType.ToString()}");

            UnsignedIntegerElement trackFlagEnabledElement = MatroskaDocTypes.FlagEnabled.GetInstance();

            trackFlagEnabledElement.Value = (ulong)(FlagEnabled ? 1 : 0);

            UnsignedIntegerElement trackFlagDefaultElement = MatroskaDocTypes.FlagDefault.GetInstance();

            trackFlagDefaultElement.Value = (ulong)(FlagDefault ? 1 : 0);

            UnsignedIntegerElement trackFlagForcedElement = MatroskaDocTypes.FlagForced.GetInstance();

            trackFlagForcedElement.Value = (ulong)(FlagForced ? 1 : 0);

            UnsignedIntegerElement trackFlagLacingElement = MatroskaDocTypes.FlagLacing.GetInstance();

            trackFlagLacingElement.Value = (ulong)(FlagLacing ? 1 : 0);

            UnsignedIntegerElement trackMinCacheElement = MatroskaDocTypes.MinCache.GetInstance();

            trackMinCacheElement.Value = (ulong)MinCache;

            UnsignedIntegerElement trackMaxBlockAddIdElement = MatroskaDocTypes.MaxBlockAdditionID.GetInstance();

            trackMaxBlockAddIdElement.Value = (ulong)MaxBlockAdditionalId;

            StringElement trackNameElement = MatroskaDocTypes.Name.GetInstance();

            trackNameElement.Value = Name;

            StringElement trackLangElement = MatroskaDocTypes.Language.GetInstance();

            trackLangElement.Value = Language;

            StringElement trackCodecIdElement = MatroskaDocTypes.CodecID.GetInstance();

            trackCodecIdElement.Value = CodecId;

            trackEntryElement.AddChildElement(trackNumberElement);
            trackEntryElement.AddChildElement(trackUIDElement);
            trackEntryElement.AddChildElement(trackTypeElement);

            trackEntryElement.AddChildElement(trackFlagEnabledElement);
            trackEntryElement.AddChildElement(trackFlagDefaultElement);
            trackEntryElement.AddChildElement(trackFlagForcedElement);
            trackEntryElement.AddChildElement(trackFlagLacingElement);
            trackEntryElement.AddChildElement(trackMinCacheElement);
            trackEntryElement.AddChildElement(trackMaxBlockAddIdElement);

            trackEntryElement.AddChildElement(trackNameElement);
            trackEntryElement.AddChildElement(trackLangElement);
            trackEntryElement.AddChildElement(trackCodecIdElement);

            if (CodecPrivate != null && CodecPrivate.Length != CodecPrivate.Position)
            {
                BinaryElement trackCodecPrivateElement = MatroskaDocTypes.CodecPrivate.GetInstance();
                trackCodecPrivateElement.Data = CodecPrivate;
                trackEntryElement.AddChildElement(trackCodecPrivateElement);
            }

            UnsignedIntegerElement trackDefaultDurationElement = MatroskaDocTypes.DefaultDuration.GetInstance();

            trackDefaultDurationElement.Value = DefaultDuration;

            UnsignedIntegerElement trackCodecDecodeAllElement = MatroskaDocTypes.CodecDecodeAll.GetInstance();

            trackCodecDecodeAllElement.Value = (ulong)(CodecDecodeAll ? 0 : 1);

            trackEntryElement.AddChildElement(trackDefaultDurationElement);
            trackEntryElement.AddChildElement(trackCodecDecodeAllElement);

            if (overlayUIDs.Count != 0)
            {
                foreach (ulong overlay in overlayUIDs)
                {
                    UnsignedIntegerElement trackOverlayElement = MatroskaDocTypes.TrackOverlay.GetInstance();
                    trackOverlayElement.Value = overlay;
                    trackEntryElement.AddChildElement(trackOverlayElement);
                }
            }

            // Now we add the audio/video dependant sub-elements
            if (this.TrackType == TrackType.Video)
            {
                MasterElement trackVideoElement = MatroskaDocTypes.Video.GetInstance();

                UnsignedIntegerElement trackVideoPixelWidthElement = MatroskaDocTypes.PixelWidth.GetInstance();
                trackVideoPixelWidthElement.Value = (ulong)this.video.PixelWidth;

                UnsignedIntegerElement trackVideoPixelHeightElement = MatroskaDocTypes.PixelHeight.GetInstance();
                trackVideoPixelHeightElement.Value = (ulong)this.video.PixelHeight;

                UnsignedIntegerElement trackVideoDisplayWidthElement = MatroskaDocTypes.DisplayWidth.GetInstance();
                trackVideoDisplayWidthElement.Value = (ulong)this.video.DisplayWidth;

                UnsignedIntegerElement trackVideoDisplayHeightElement = MatroskaDocTypes.DisplayHeight.GetInstance();
                trackVideoDisplayHeightElement.Value = (ulong)this.video.DisplayHeight;

                trackVideoElement.AddChildElement(trackVideoPixelWidthElement);
                trackVideoElement.AddChildElement(trackVideoPixelHeightElement);
                trackVideoElement.AddChildElement(trackVideoDisplayWidthElement);
                trackVideoElement.AddChildElement(trackVideoDisplayHeightElement);

                trackEntryElement.AddChildElement(trackVideoElement);
            }
            else if (this.TrackType == TrackType.Audio)
            {
                MasterElement trackAudioElement = MatroskaDocTypes.Audio.GetInstance();

                UnsignedIntegerElement trackAudioChannelsElement = MatroskaDocTypes.Channels.GetInstance();
                trackAudioChannelsElement.Value = (ulong)this.audio.Channels;

                UnsignedIntegerElement trackAudioBitDepthElement = MatroskaDocTypes.BitDepth.GetInstance();
                trackAudioBitDepthElement.Value = this.audio.BitDepth;

                FloatElement trackAudioSamplingRateElement = MatroskaDocTypes.SamplingFrequency.GetInstance();
                trackAudioSamplingRateElement.Value = this.audio.SamplingFrequency;

                FloatElement trackAudioOutputSamplingFrequencyElement = MatroskaDocTypes.OutputSamplingFrequency.GetInstance();
                trackAudioOutputSamplingFrequencyElement.Value = this.audio.OutputSamplingFrequency;

                trackAudioElement.AddChildElement(trackAudioChannelsElement);
                trackAudioElement.AddChildElement(trackAudioBitDepthElement);
                trackAudioElement.AddChildElement(trackAudioSamplingRateElement);
                trackAudioElement.AddChildElement(trackAudioOutputSamplingFrequencyElement);

                trackEntryElement.AddChildElement(trackAudioElement);
            }
            if (joinUIDs != null)
            {
                MasterElement trackOpElement   = MatroskaDocTypes.TrackOperation.GetInstance();
                MasterElement trackJoinElement = MatroskaDocTypes.TrackJoinBlocks.GetInstance();
                foreach (ulong uid in joinUIDs)
                {
                    UnsignedIntegerElement joinUidElement = MatroskaDocTypes.TrackJoinUID.GetInstance();
                    joinUidElement.Value = uid;
                    trackJoinElement.AddChildElement(joinUidElement);
                }
                trackOpElement.AddChildElement(trackJoinElement);
                trackEntryElement.AddChildElement(trackOpElement);
            }
            return(trackEntryElement);
        }
Ejemplo n.º 25
0
		bool ReadNextObject (BinaryElement element, BinaryReader reader)
		{
			if (element == BinaryElement.End)
			{
				_manager.DoFixups();

				_manager.RaiseDeserializationEvent();
				return false;
			}

			SerializationInfo info;
			long objectId;

			ReadObject (element, reader, out objectId, out _lastObject, out info);

			if (objectId != 0) {
				RegisterObject (objectId, _lastObject, info, 0, null, null);
				_lastObjectID = objectId;		
			}
	
			return true;
		}
Ejemplo n.º 26
0
 internal void WriteBinaryElement(BinaryElement _element)
 {
     Write((byte)_element);
 }
Ejemplo n.º 27
0
        public static object ReadMethodCall(BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, BinaryFormatter formatter)
        {
            if (elem != BinaryElement.MethodCall)
            {
                throw new SerializationException("Invalid format. Expected BinaryElement.MethodCall, found " + elem);
            }
            MethodFlags methodFlags = (MethodFlags)reader.ReadInt32();

            if (reader.ReadByte() != 18)
            {
                throw new SerializationException("Invalid format");
            }
            string value = reader.ReadString();

            if (reader.ReadByte() != 18)
            {
                throw new SerializationException("Invalid format");
            }
            string value2 = reader.ReadString();

            object[] array  = null;
            object   value3 = null;
            object   value4 = null;

            object[] array2  = null;
            Header[] headers = null;
            Type[]   value5  = null;
            if ((methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0)
            {
                uint num = reader.ReadUInt32();
                array = new object[num];
                int num2 = 0;
                while ((long)num2 < (long)((ulong)num))
                {
                    Type typeFromCode = BinaryCommon.GetTypeFromCode((int)reader.ReadByte());
                    array[num2] = ObjectReader.ReadPrimitiveTypeValue(reader, typeFromCode);
                    num2++;
                }
            }
            if ((methodFlags & MethodFlags.NeedsInfoArrayMask) > (MethodFlags)0)
            {
                ObjectReader objectReader = new ObjectReader(formatter);
                object       obj;
                objectReader.ReadObjectGraph(reader, hasHeaders, out obj, out headers);
                object[] array3 = (object[])obj;
                if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0)
                {
                    array = array3;
                }
                else
                {
                    int num3 = 0;
                    if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > (MethodFlags)0)
                    {
                        if (array3.Length > 1)
                        {
                            array = (object[])array3[num3++];
                        }
                        else
                        {
                            array = new object[0];
                        }
                    }
                    if ((methodFlags & MethodFlags.GenericArguments) > (MethodFlags)0)
                    {
                        value5 = (Type[])array3[num3++];
                    }
                    if ((methodFlags & MethodFlags.IncludesSignature) > (MethodFlags)0)
                    {
                        value3 = array3[num3++];
                    }
                    if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > (MethodFlags)0)
                    {
                        value4 = array3[num3++];
                    }
                    if (num3 < array3.Length)
                    {
                        array2 = (object[])array3[num3];
                    }
                }
            }
            else
            {
                reader.ReadByte();
            }
            if (array == null)
            {
                array = new object[0];
            }
            string value6 = null;

            if (headerHandler != null)
            {
                value6 = (headerHandler(headers) as string);
            }
            MethodCall methodCall = new MethodCall(new Header[]
            {
                new Header("__MethodName", value),
                new Header("__MethodSignature", value3),
                new Header("__TypeName", value2),
                new Header("__Args", array),
                new Header("__CallContext", value4),
                new Header("__Uri", value6),
                new Header("__GenericArguments", value5)
            });

            if (array2 != null)
            {
                foreach (DictionaryEntry dictionaryEntry in array2)
                {
                    methodCall.Properties[(string)dictionaryEntry.Key] = dictionaryEntry.Value;
                }
            }
            return(methodCall);
        }
Ejemplo n.º 28
0
		public void ReadObjectGraph (BinaryElement elem, BinaryReader reader, bool readHeaders, out object result, out Header[] headers)
		{
			headers = null;

			// Reads the objects. The first object in the stream is the
			// root object.
			bool next = ReadNextObject (elem, reader);
			if (next) {
				do {
					if (readHeaders && (headers == null))
						headers = (Header[])CurrentObject;
					else
						if (_rootObjectID == 0) _rootObjectID = _lastObjectID;
				} while (ReadNextObject (reader));
			}

			result = _manager.GetObject (_rootObjectID);
		}
Ejemplo n.º 29
0
        public static object ReadMethodResponse(BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, BinaryFormatter formatter)
        {
            if (elem != BinaryElement.MethodResponse)
            {
                throw new SerializationException("Invalid format. Expected BinaryElement.MethodResponse, found " + elem);
            }
            MethodFlags   methodFlags   = (MethodFlags)reader.ReadByte();
            ReturnTypeTag returnTypeTag = (ReturnTypeTag)reader.ReadByte();
            bool          flag          = (methodFlags & MethodFlags.IncludesLogicalCallContext) > (MethodFlags)0;

            reader.ReadByte();
            reader.ReadByte();
            object ret = null;

            object[]           array   = null;
            LogicalCallContext callCtx = null;
            Exception          ex      = null;

            object[] array2  = null;
            Header[] headers = null;
            if ((byte)(returnTypeTag & ReturnTypeTag.PrimitiveType) > 0)
            {
                Type typeFromCode = BinaryCommon.GetTypeFromCode((int)reader.ReadByte());
                ret = ObjectReader.ReadPrimitiveTypeValue(reader, typeFromCode);
            }
            if ((methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0)
            {
                uint num = reader.ReadUInt32();
                array = new object[num];
                int num2 = 0;
                while ((long)num2 < (long)((ulong)num))
                {
                    Type typeFromCode2 = BinaryCommon.GetTypeFromCode((int)reader.ReadByte());
                    array[num2] = ObjectReader.ReadPrimitiveTypeValue(reader, typeFromCode2);
                    num2++;
                }
            }
            if (flag || (byte)(returnTypeTag & ReturnTypeTag.ObjectType) > 0 || (byte)(returnTypeTag & ReturnTypeTag.Exception) > 0 || (methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0 || (methodFlags & MethodFlags.ArgumentsInMultiArray) > (MethodFlags)0)
            {
                ObjectReader objectReader = new ObjectReader(formatter);
                object       obj;
                objectReader.ReadObjectGraph(reader, hasHeaders, out obj, out headers);
                object[] array3 = (object[])obj;
                if ((byte)(returnTypeTag & ReturnTypeTag.Exception) > 0)
                {
                    ex = (Exception)array3[0];
                    if (flag)
                    {
                        callCtx = (LogicalCallContext)array3[1];
                    }
                }
                else if ((methodFlags & MethodFlags.NoArguments) > (MethodFlags)0 || (methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0)
                {
                    int num3 = 0;
                    if ((byte)(returnTypeTag & ReturnTypeTag.ObjectType) > 0)
                    {
                        ret = array3[num3++];
                    }
                    if (flag)
                    {
                        callCtx = (LogicalCallContext)array3[num3++];
                    }
                    if (num3 < array3.Length)
                    {
                        array2 = (object[])array3[num3];
                    }
                }
                else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0)
                {
                    array = array3;
                }
                else
                {
                    int num4 = 0;
                    array = (object[])array3[num4++];
                    if ((byte)(returnTypeTag & ReturnTypeTag.ObjectType) > 0)
                    {
                        ret = array3[num4++];
                    }
                    if (flag)
                    {
                        callCtx = (LogicalCallContext)array3[num4++];
                    }
                    if (num4 < array3.Length)
                    {
                        array2 = (object[])array3[num4];
                    }
                }
            }
            else
            {
                reader.ReadByte();
            }
            if (headerHandler != null)
            {
                headerHandler(headers);
            }
            if (ex != null)
            {
                return(new ReturnMessage(ex, methodCallMessage));
            }
            int           outArgsCount  = (array == null) ? 0 : array.Length;
            ReturnMessage returnMessage = new ReturnMessage(ret, array, outArgsCount, callCtx, methodCallMessage);

            if (array2 != null)
            {
                foreach (DictionaryEntry dictionaryEntry in array2)
                {
                    returnMessage.Properties[(string)dictionaryEntry.Key] = dictionaryEntry.Value;
                }
            }
            return(returnMessage);
        }
Ejemplo n.º 30
0
 internal void WriteBinaryElement(BinaryElement _element)
 {
     Write((byte)_element);
 }
Ejemplo n.º 31
0
		public static object ReadMethodResponse (BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, BinaryFormatter formatter)
		{
			if (elem != BinaryElement.MethodResponse) throw new SerializationException("Invalid format. Expected BinaryElement.MethodResponse, found " +  elem);

			MethodFlags flags = (MethodFlags) reader.ReadByte ();
			ReturnTypeTag typeTag = (ReturnTypeTag) reader.ReadByte ();
			bool hasContextInfo = (flags & MethodFlags.IncludesLogicalCallContext) > 0;

			// FIXME: find a meaning for those 2 bytes
			reader.ReadByte();
			reader.ReadByte();

			object returnValue = null;
			object[] outArgs = null;
			LogicalCallContext callContext = null;
			Exception exception = null;
			object[] extraProperties = null;
			Header[] headers = null;

			if ((typeTag & ReturnTypeTag.PrimitiveType) > 0)
			{
				Type type = BinaryCommon.GetTypeFromCode (reader.ReadByte());
				returnValue = ObjectReader.ReadPrimitiveTypeValue (reader, type);
			}

			if ((flags & MethodFlags.PrimitiveArguments) > 0)
			{
				uint count = reader.ReadUInt32();
				outArgs = new object[count];
				for (int n=0; n<count; n++) {
					Type type = BinaryCommon.GetTypeFromCode (reader.ReadByte());
					outArgs[n] = ObjectReader.ReadPrimitiveTypeValue (reader, type);
				}
			}

			if (hasContextInfo || (typeTag & ReturnTypeTag.ObjectType) > 0 || 
				(typeTag & ReturnTypeTag.Exception) > 0 ||
				(flags & MethodFlags.ArgumentsInSimpleArray) > 0 || 
				(flags & MethodFlags.ArgumentsInMultiArray) > 0)
			{
				// There objects that need to be deserialized using an ObjectReader

				ObjectReader objectReader = new ObjectReader (formatter);
				object result;
				objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers);
				object[] msgInfo = (object[]) result;

				if ((typeTag & ReturnTypeTag.Exception) > 0) {
					exception = (Exception) msgInfo[0];
					if (hasContextInfo) callContext = (LogicalCallContext)msgInfo[1];
				}
				else if ((flags & MethodFlags.NoArguments) > 0 || (flags & MethodFlags.PrimitiveArguments) > 0) {
					int n = 0;
					if ((typeTag & ReturnTypeTag.ObjectType) > 0) returnValue = msgInfo [n++];
					if (hasContextInfo) callContext = (LogicalCallContext)msgInfo[n++];
					if (n < msgInfo.Length) extraProperties = (object[]) msgInfo[n];
				}
				else if ((flags & MethodFlags.ArgumentsInSimpleArray) > 0) {
					outArgs = msgInfo;
				}
				else {
					int n = 0;
					outArgs = (object[]) msgInfo[n++];
					if ((typeTag & ReturnTypeTag.ObjectType) > 0) returnValue = msgInfo[n++];
					if (hasContextInfo) callContext = (LogicalCallContext)msgInfo[n++];
					if (n < msgInfo.Length) extraProperties = (object[]) msgInfo[n];
				}
			}
			else {
				reader.ReadByte ();	// Reads the stream ender
			}

			if (headerHandler != null) 
				headerHandler(headers);

			if (exception != null)
				return new ReturnMessage (exception, methodCallMessage);
			else
			{
				int argCount = (outArgs!=null) ? outArgs.Length : 0;
				ReturnMessage result = new ReturnMessage (returnValue, outArgs, argCount, callContext, methodCallMessage);

				if (extraProperties != null) {
					foreach (DictionaryEntry entry in extraProperties)
						result.Properties [(string)entry.Key] = entry.Value;
				}

				return result;
			}
		}
        public static object ReadMethodCall(BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, BinaryFormatter formatter)
        {
            BinaryElement elem = (BinaryElement)reader.ReadByte(); // The element code

            return(ReadMethodCall(elem, reader, hasHeaders, headerHandler, formatter));
        }
Ejemplo n.º 33
0
		// Reads an object from the stream. The object is registered in the ObjectManager.
		// The result can be either the object instance
		// or the id of the object (when what is found in the stream is an object reference).
		// If an object instance is read, the objectId is set to 0.
		
		private void ReadObject (BinaryElement element, BinaryReader reader, out long objectId, out object value, out SerializationInfo info)
		{
			switch (element)
			{
				case BinaryElement.RefTypeObject:
					ReadRefTypeObjectInstance (reader, out objectId, out value, out info);
					break;

				case BinaryElement.UntypedRuntimeObject:
					ReadObjectInstance (reader, true, false, out objectId, out value, out info);
					break;

				case BinaryElement.UntypedExternalObject:
					ReadObjectInstance (reader, false, false, out objectId, out value, out info);
					break;

				case BinaryElement.RuntimeObject:
					ReadObjectInstance (reader, true, true, out objectId, out value, out info);
					break;

				case BinaryElement.ExternalObject:
					ReadObjectInstance (reader, false, true, out objectId, out value, out info);
					break;

				case BinaryElement.String:
					info = null;
					ReadStringIntance (reader, out objectId, out value);
					break;

				case BinaryElement.GenericArray:
					info = null;
					ReadGenericArray (reader, out objectId, out value);
					break;


				case BinaryElement.BoxedPrimitiveTypeValue:
					value = ReadBoxedPrimitiveTypeValue (reader);
					objectId = 0;
					info = null;
					break;

				case BinaryElement.NullValue:
					value = null;
					objectId = 0;
					info = null;
					break;

				case BinaryElement.Assembly:
					ReadAssembly (reader);
					ReadObject ((BinaryElement)reader.ReadByte (), reader, out objectId, out value, out info);
					break;

				case BinaryElement.ArrayFiller8b:
					value = new ArrayNullFiller(reader.ReadByte());
					objectId = 0;
					info = null;
					break;

				case BinaryElement.ArrayFiller32b:
					value = new ArrayNullFiller(reader.ReadInt32());
					objectId = 0;
					info = null;
					break;

				case BinaryElement.ArrayOfPrimitiveType:
					ReadArrayOfPrimitiveType (reader, out objectId, out value);
					info = null;
					break;

				case BinaryElement.ArrayOfObject:
					ReadArrayOfObject (reader, out objectId, out value);
					info = null;
					break;

				case BinaryElement.ArrayOfString:
					ReadArrayOfString (reader, out objectId, out value);
					info = null;
					break;

				default:
					throw new SerializationException ("Unexpected binary element: " + (int)element);
			}
		}
Ejemplo n.º 34
0
 public BTreeElement(int _max_elements, BinaryElement <TKey, TValue> _b_element)
 {
     Init(_max_elements, _b_element);
 }
Ejemplo n.º 35
0
        private void ReadValue(BinaryReader reader, object parentObject, long parentObjectId, SerializationInfo info, Type valueType, string fieldName, MemberInfo memberInfo, int[] indices)
        {
            // Reads a value from the stream and assigns it to the member of an object

            object val;

            if (BinaryCommon.IsPrimitive(valueType) && !IsGeneric(memberInfo))
            {
                val = ReadPrimitiveTypeValue(reader, valueType);
                SetObjectValue(parentObject, fieldName, memberInfo, info, val, valueType, indices);
                return;
            }

            // Gets the object

            BinaryElement element = (BinaryElement)reader.ReadByte();

            if (element == BinaryElement.ObjectReference)
            {
                // Just read the id of the referred object and record a fixup
                long childObjectId = (long)reader.ReadUInt32();
                RecordFixup(parentObjectId, childObjectId, parentObject, info, fieldName, memberInfo, indices);
                return;
            }

            long objectId;
            SerializationInfo objectInfo;

            ReadObject(element, reader, out objectId, out val, out objectInfo);

            // There are two cases where the object cannot be assigned to the parent
            // and a fixup must be used:
            //  1) When what has been read is not an object, but an id of an object that
            //     has not been read yet (an object reference). This is managed in the
            //     previous block of code.
            //  2) When the read object is a value type object. Value type fields hold
            //     copies of objects, not references. Thus, if the value object that
            //     has been read has pending fixups, those fixups would be made to the
            //     boxed copy in the ObjectManager, and not in the required object instance

            // First of all register the fixup, and then the object. ObjectManager is more
            // efficient if done in this order

            bool hasFixup = false;

            if (objectId != 0)
            {
                if (val.GetType().IsValueType)
                {
                    RecordFixup(parentObjectId, objectId, parentObject, info, fieldName, memberInfo, indices);
                    hasFixup = true;
                }

                // Register the value

                if (info == null && !(parentObject is Array))
                {
                    RegisterObject(objectId, val, objectInfo, parentObjectId, memberInfo, null);
                }
                else
                {
                    RegisterObject(objectId, val, objectInfo, parentObjectId, null, indices);
                }
            }
            // Assign the value to the parent object, unless there is a fixup

            if (!hasFixup)
            {
                SetObjectValue(parentObject, fieldName, memberInfo, info, val, valueType, indices);
            }
        }
        internal void ReadTypeMetaData(RSBinaryReader _binaryReader, BinaryElement _binaryElement)
        {
            // Read assembly info
            if (_binaryElement == BinaryElement.ASSEMBLY)
            {
                UInt32 		_assemblyID			= _binaryReader.ReadUInt32();
                string 		_assemblyFullName	= _binaryReader.ReadString();
                Assembly 	_assembly			= Assembly.Load(_assemblyFullName);

                if (_assembly == null)
                    throw new Exception(string.Format("[RS] Couldnt load assembly with name={0}.", _assemblyFullName));

                // Add assembly info to cache
                m_cachedAssemblies.Add(_assembly, _assemblyID);

                // Read next element
                _binaryElement					= _binaryReader.ReadBinaryElement();
            }

            // Read type info
            if (_binaryElement == BinaryElement.TYPE)
            {
                UInt32 		_assemblyID			= _binaryReader.ReadUInt32();
                UInt32 		_typeID				= _binaryReader.ReadUInt32();
                string 		_typeFullName		= _binaryReader.ReadString();
                Assembly 	_assembly			= GetAssembly(_assemblyID);

                if (_assembly == null)
                    throw new Exception(string.Format("[RS] Assembly with ID={0} couldnt be found.", _assemblyID));

                Type 		_newType			= _assembly.GetType(_typeFullName, true);

                // Add type info to cache
                m_cachedObjectTypes.Add(_newType, _typeID);
            }
        }