Esempio n. 1
0
        public void writeObject(object obj)
        {
            System.Type type = obj.GetType();
            if (type == typeof(bool))
            {
                write((bool)obj);
            }
            else if (type == typeof(byte))
            {
                write((byte)obj);
            }
            else if (type == typeof(sbyte))
            {
                write((sbyte)obj);
            }
            else if (type == typeof(Int16))
            {
                write((Int16)obj);
            }
            else if (type == typeof(UInt16))
            {
                write((UInt16)obj);
            }
            else if (type == typeof(Int32))
            {
                write((Int32)obj);
            }
            else if (type == typeof(UInt32))
            {
                write((UInt32)obj);
            }
            else if (type == typeof(Int64))
            {
                write((Int64)obj);
            }
            else if (type == typeof(UInt64))
            {
                write((UInt64)obj);
            }
            else if (type == typeof(Single))
            {
                write((Single)obj);
            }
            else if (type == typeof(string))
            {
                write((string)obj);
            }
            else if (type.BaseType == typeof(Array))
            {
                write((Array)obj);
            }
            else
            {
                ByteStream.Serializer serializer = getSerializer(type);
                if (serializer != null)
                {
                    serializer(this, ref obj);
                    return;
                }

                var streamable = (obj as IStreamable);
                if (streamable != null)
                {
                    streamable.serialize(this);
                    return;
                }

                throw new StreamException(string.Format("Can't write object {0}", type.ToString()));
            }
        }
Esempio n. 2
0
        public void readObject(ref object obj, Type type)
        {
            if (type == typeof(bool))
            {
                obj = readBool();
            }
            else if (type == typeof(byte))
            {
                obj = readByte();
            }
            else if (type == typeof(sbyte))
            {
                obj = readSByte();
            }
            else if (type == typeof(Int16))
            {
                obj = readInt16();
            }
            else if (type == typeof(UInt16))
            {
                obj = readUInt16();
            }
            else if (type == typeof(Int32))
            {
                obj = readInt32();
            }
            else if (type == typeof(UInt32))
            {
                obj = readUInt32();
            }
            else if (type == typeof(Int64))
            {
                obj = readInt64();
            }
            else if (type == typeof(UInt64))
            {
                obj = readUInt64();
            }
            else if (type == typeof(Single))
            {
                obj = readSingle();
            }
            else if (type == typeof(string))
            {
                obj = readString();
            }
            else if (type.BaseType == typeof(Array))
            {
                obj = ((Array)obj).serialize(this);
            }
            else
            {
                ByteStream.Serializer serializer = getSerializer(type);
                if (serializer != null)
                {
                    serializer(this, ref obj);
                    return;
                }

                var streamable = (obj as IStreamable);
                if (streamable != null)
                {
                    streamable.serialize(this);
                    return;
                }

                throw new StreamException(string.Format("Can't read object {0}", type.ToString()));
            }
        }
Esempio n. 3
0
 public void registerSerializer(Type type, ByteStream.Serializer serializer)
 {
     _marshalStream.registerSerializer(type, serializer);
     _unmarshalStream.registerSerializer(type, serializer);
 }