public static void WriteObject <T>(Stream stream, T ob, bool littleEndian)
        {
            if (!TCPBase.Ordering.ContainsKey(typeof(T)))
            {
                TCPBase.AddMessageObject(typeof(T));
            }

            var list = TCPBase.Ordering[typeof(T)];

            foreach (var prop in list)
            {
                Type curr = prop.PropertyType;

                if (curr == typeof(double))
                {
                    WriteNumber(stream, (double)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(float))
                {
                    WriteNumber(stream, (float)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(ushort))
                {
                    WriteNumber(stream, (ushort)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(short))
                {
                    WriteNumber(stream, (short)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(int))
                {
                    WriteNumber(stream, (int)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(uint))
                {
                    WriteNumber(stream, (uint)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(long))
                {
                    WriteNumber(stream, (long)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(ulong))
                {
                    WriteNumber(stream, (ulong)prop.GetValue(ob, null), littleEndian);
                }
                else if (curr == typeof(byte))
                {
                    stream.Write(new byte[] { (byte)prop.GetValue(ob, null) }, 0, 1);
                }
            }

            string w = "";
        }
        public static T ReadObject <T>(Stream stream, bool littleEndian, out bool error) where T : new()
        {
            T ob = new T();

            if (!TCPBase.Ordering.ContainsKey(typeof(T)))
            {
                TCPBase.AddMessageObject(typeof(T));
            }

            var list = TCPBase.Ordering[typeof(T)];

            foreach (var prop in list)
            {
                Type curr = prop.PropertyType;

                if (curr == typeof(double))
                {
                    double val = ReadDouble(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(float))
                {
                    float val = ReadFloat(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(ushort))
                {
                    ushort val = ReadUShort(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(short))
                {
                    short val = ReadShort(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(int))
                {
                    int val = ReadInt(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(uint))
                {
                    uint val = ReadUInt(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(long))
                {
                    long val = ReadLong(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(ulong))
                {
                    ulong val = ReadULong(stream, littleEndian, out error);

                    if (error)
                    {
                        return(default(T));
                    }

                    prop.SetValue(ob, val);
                }
                else if (curr == typeof(byte))
                {
                    byte[] val = Read(stream, 1);

                    if (val == null)
                    {
                        error = true;
                        return(default(T));
                    }

                    prop.SetValue(ob, val[0]);
                }
            }

            error = false;
            return(ob);
        }