Example #1
0
        public static void _SerializerSwitch(Stream stream, object value, ObjectList objList)
        {
            if (objList != null)
            {
                int index = objList.IndexOf(value);
                if (index != -1)
                {
                    value = new ObjectRef(index);
                }
            }

            if (value == null)
            {
                Primitives.WritePrimitive(stream, (ushort)0, objList);
            }
            else
            {
                TypeData typeData;
                if (!s_typeMap.TryGetValue(value.GetType(), out typeData))
                    throw new InvalidOperationException(String.Format("Unknown type = {0}", value.GetType().FullName));

                Primitives.WritePrimitive(stream, typeData.TypeID, objList);
                typeData.serializer(stream, value, objList);
            }
        }
Example #2
0
        internal static void Serialize(Stream stream, object data, ObjectList objList)
        {
            D("Serializing {0}", data.GetType().Name);

            #if GENERATE_SWITCH
            s_serializerSwitch(stream, data, objList);
            #else
            _SerializerSwitch(stream, data, objList);
            #endif
        }
Example #3
0
        public static void _DeserializerSwitch(Stream stream, out object value, ObjectList objList)
        {
            ushort num;
            Primitives.ReadPrimitive(stream, out num, objList);

            if (num == 0)
            {
                value = null;
                return;
            }
            else if (num == 1)
            {
                ObjectRef ref2;
                Primitives.ReadPrimitive(stream, out ref2, objList);
                if (objList == null)
                {
                    value = null;
                    return;
                }
                value = objList.GetAt(ref2);
                return;

            }
            else
            {
                TypeData typeData;
                if (!s_typeID_TypeData.TryGetValue(num, out typeData))
                    throw new InvalidOperationException(String.Format("Unknown typeId = {0}", num));

                typeData.deserializer(stream, out value, objList);
            }
        }
Example #4
0
        internal static object Deserialize(Stream stream, ObjectList objList)
        {
            D("Deserializing");

            object o;
            #if GENERATE_SWITCH
            s_deserializerSwitch(stream, out o, objList);
            #else
            _DeserializerSwitch(stream, out o, objList);
            #endif
            return o;
        }