public void SerialiseObject(MfcObject mfcObject)
        {
            if (mfcObject == null)
            {
                _stream.Write((ushort)NullTag);
                return;
            }

            int prevObjectIndex = _loadedObjects.IndexOf(mfcObject);

            if (prevObjectIndex >= 0)
            {
                // We have already serialised this object and do not need to do so again
                if (prevObjectIndex >= BigObjectTag)
                {
                    throw new NotImplementedException("Object count >= 0x7fff not yet supported");
                }
                _stream.Write((ushort)prevObjectIndex);
                return;
            }

            // A new object, possibly with a new class
            _loadedObjects.Add(mfcObject);
            MfcClass mfcClass       = _classRegistry.GetMfcClass(mfcObject.GetType());
            int      prevClassIndex = _loadedClasses.IndexOf(mfcClass);

            if (prevClassIndex <= 0)
            {
                // A new class
                _loadedClasses.Add(mfcClass);
                _stream.Write((ushort)NewClassTag);
                _stream.Write((ushort)mfcClass.SchemaVersion);
                _stream.Write((ushort)mfcClass.Name.Length);
                _stream.WriteAsciiString(mfcClass.Name);
            }
            else
            {
                // A previously written class
                _stream.Write((ushort)(prevClassIndex | ClassTag));
            }

            mfcObject.Serialise(this);
        }
Exemple #2
0
        /// <summary>
        /// Deserialises an object of type T without reading in the header.
        /// This implies it must be a new object and not one that has already
        /// been loaded since there is no object tag to reference the loaded list.
        /// </summary>
        public T DeserialiseObjectNoHeader <T>() where T : MfcObject
        {
            MfcClass mfcClass = _classRegistry.GetMfcClass(typeof(T));

            return(DeserialiseNewObject <T>(mfcClass));
        }