Пример #1
0
 /// <summary>
 /// Verify that the given SerializedPacket is of the given type
 /// </summary>
 /// <param name="s">The packet</param>
 /// <param name="type">The type to check for</param>
 public static void VerifyPacket(SerializedPacket s, int type)
 {
     if (s.Type != type && s.Type != -type)
     {
         throw new Exception("This packet type is not appropriate for this function");
     }
 }
Пример #2
0
        public static SerializedPacket NullPacket(int type)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = -type;
            return(packet);
        }
 public SubmissionStatusModel( SerializedPacket p )
 {
     SerializedPacket.VerifyPacket( p, this.GetClassId() );
     this.id_ = SerializedPacket.DeserializeGuid( p.GetPart( 0 ) );
     this.submission_status_ = (Status)SerializedPacket.DeserializeInt( p.GetPart( 1 ) );
     this.role_ = SerializedPacket.DeserializeString( p.GetPart( 2 ) );
 }
Пример #4
0
 public DeckMessage( Message parent, SerializedPacket p )
     : base(parent, p)
 {
     this.HumanName = SerializedPacket.DeserializeString( p.GetNextPart() );
     this.Disposition = (DeckDisposition)SerializedPacket.DeserializeLong( p.GetNextPart() );
     this.DeckBackgroundColor = SerializedPacket.DeserializeColor( p.GetNextPart() );
 }
Пример #5
0
        /// <summary>
        /// Serialize a GUID
        /// </summary>
        /// <param name="g">The guid</param>
        /// <returns>The packet</returns>
        public static SerializedPacket SerializeMD5(Guid g)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.ByteArrayClassId;
            packet.Add(g.ToByteArray());
            return(packet);
        }
Пример #6
0
        /// <summary>
        /// Serialize a Float
        /// </summary>
        /// <param name="f">The float</param>
        /// <returns>The Packet</returns>
        public static SerializedPacket SerializeFloat(float f)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.FloatId;
            packet.Add(BitConverter.GetBytes(f));
            return(packet);
        }
Пример #7
0
        /// <summary>
        /// Serialize a ByteArray
        /// </summary>
        /// <param name="i">The array</param>
        /// <returns>The Packet</returns>
        public static SerializedPacket SerializeByteArray(byte[] i)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.ByteArrayId;
            packet.Data.AddRange(i);
            return(packet);
        }
Пример #8
0
        /// <summary>
        /// Serialize a Boolean Value
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public static SerializedPacket SerializeBool(bool i)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.BoolId;
            packet.Add((i) ? (byte)1 : (byte)0);
            return(packet);
        }
Пример #9
0
        /// <summary>
        /// Serialize a Byte Value
        /// </summary>
        /// <param name="i">The Byte</param>
        /// <returns>The Packet</returns>
        public static SerializedPacket SerializeByte(byte i)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.ByteId;
            packet.Data.Add(i);
            return(packet);
        }
Пример #10
0
 /// <summary>
 /// Deserialize a String
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The string</returns>
 public static string DeserializeString(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.StringId);
     if (s.Type < 0)
     {
         return(null);
     }
     return(System.Text.Encoding.ASCII.GetString((byte[])s.Data.ToArray(typeof(byte))));
 }
Пример #11
0
 /// <summary>
 /// Deserialize a Byte Value
 /// </summary>
 /// <param name="s">The Packet</param>
 /// <returns>The byte</returns>
 public static byte DeserializeByte(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.ByteId);
     if (s.Data.Count != 1)
     {
         throw new Exception("Incorrect Data Length");
     }
     return((byte)s.Data[0]);
 }
Пример #12
0
 /// <summary>
 /// Deserialize a Boolean Value
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public static bool DeserializeBool(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.BoolId);
     if (s.Data.Count != 1)
     {
         throw new Exception("Incorrect Data Length");
     }
     return(((byte)s.Data[0] == 1) ? true : false);
 }
Пример #13
0
 /// <summary>
 /// Deserialize a GUID
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The guid</returns>
 public static Guid DeserializeMD5(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.ByteArrayClassId);
     if (s.Data.Count != 16)
     {
         throw new Exception("Incorrect Data Length");
     }
     return(new Guid((byte[])s.Data.ToArray(typeof(byte))));
 }
Пример #14
0
 public void Add(SerializedPacket p)
 {
     if (this.NumChildren == -1 && this.Data.Count != 0)
     {
         throw new Exception("Can't Add Both Binary and Object Data");
     }
     this.Data.Add(p);
     this.NumChildren = this.Data.Count;
     this.CachedSize  = -1;
 }
Пример #15
0
        /// <summary>
        /// Serialize a Rectangle
        /// </summary>
        /// <param name="r">The rectangle</param>
        /// <returns>The packet</returns>
        public static SerializedPacket SerializeRectangle(System.Drawing.Rectangle r)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.RectangleId;
            packet.Add(SerializeInt(r.X));
            packet.Add(SerializeInt(r.Y));
            packet.Add(SerializeInt(r.Width));
            packet.Add(SerializeInt(r.Height));
            return(packet);
        }
Пример #16
0
        /// <summary>
        /// Serialize an Int32
        /// </summary>
        /// <param name="i">The Int</param>
        /// <returns>The Packet</returns>
        public static SerializedPacket SerializeInt(int i)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.Integer32Id;
            packet.Add((byte)((i >> 0) & 0xFF));
            packet.Add((byte)((i >> 8) & 0xFF));
            packet.Add((byte)((i >> 16) & 0xFF));
            packet.Add((byte)((i >> 24) & 0xFF));
            return(packet);
        }
Пример #17
0
 /// <summary>
 /// Deserialize a Rectangle
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The rectangle</returns>
 public static System.Drawing.Rectangle DeserializeRectangle(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.RectangleId);
     if (s.Data.Count != 4)
     {
         throw new Exception("Incorrect Data Length");
     }
     return(new System.Drawing.Rectangle(DeserializeInt((SerializedPacket)s.Data[0]),
                                         DeserializeInt((SerializedPacket)s.Data[1]),
                                         DeserializeInt((SerializedPacket)s.Data[2]),
                                         DeserializeInt((SerializedPacket)s.Data[3])));
 }
Пример #18
0
        /// <summary>
        /// Serialize an IPEndPoint
        /// </summary>
        /// <param name="ep">The end point</param>
        /// <returns>The packet</returns>
        public static SerializedPacket SerializeIPEndPoint(System.Net.IPEndPoint ep)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.IPEndPointId;
            // Pack the Data
            packet.Add(SerializeInt((int)ep.AddressFamily));
            packet.Add(SerializeInt(ep.Port));
//            packet.Add( SerializeLong( ep.Address.ScopeId ) );
            packet.Add(SerializeByteArray(ep.Address.GetAddressBytes()));
            return(packet);
        }
Пример #19
0
 /// <summary>
 /// Deserialize an Int32
 /// </summary>
 /// <param name="s">The Packet</param>
 /// <returns>The int</returns>
 public static int DeserializeInt(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.Integer32Id);
     if (s.Data.Count != 4)
     {
         throw new Exception("Incorrect Data Length");
     }
     return((int)(((byte)s.Data[0] << 0) |
                  ((byte)s.Data[1] << 8) |
                  ((byte)s.Data[2] << 16) |
                  ((byte)s.Data[3] << 24)));
 }
Пример #20
0
        /// <summary>
        /// Serialize a String
        /// </summary>
        /// <param name="s">The string</param>
        /// <returns>The packet</returns>
        public static SerializedPacket SerializeString(string s)
        {
            if (s == null)
            {
                return(NullPacket(PacketTypes.StringId));
            }
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.StringId;
            packet.Data.AddRange(System.Text.Encoding.ASCII.GetBytes(s));
            return(packet);
        }
Пример #21
0
 /// <summary>
 /// Deserialize a Color struct
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The color</returns>
 public static System.Drawing.Color DeserializeColor(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.ColorId);
     if (s.Type < 0)
     {
         return(System.Drawing.Color.Empty);
     }
     if (s.Data.Count != 4)
     {
         throw new Exception("Incorrect Data Length");
     }
     return(System.Drawing.Color.FromArgb((byte)s.Data[0], (byte)s.Data[1], (byte)s.Data[2], (byte)s.Data[3]));
 }
Пример #22
0
        /// <summary>
        /// Deserialize a ByteArray
        /// </summary>
        /// <param name="s">The Packet</param>
        /// <returns>The array</returns>
        public static int[] DeserializeIntArray(SerializedPacket s)
        {
            VerifyPacket(s, PacketTypes.IntArrayId);
            ArrayList list = new ArrayList();

            for (int i = 0; i < s.Data.Count; i += 4)
            {
                list.Add((int)(((byte)s.Data[i + 0] << 0) |
                               ((byte)s.Data[i + 1] << 8) |
                               ((byte)s.Data[i + 2] << 16) |
                               ((byte)s.Data[i + 3] << 24)));
            }
            return((int[])list.ToArray(typeof(int)));
        }
Пример #23
0
        /// <summary>
        /// Serialize a Color struct
        /// </summary>
        /// <param name="c">The color</param>
        /// <returns>The packet</returns>
        public static SerializedPacket SerializeColor(System.Drawing.Color c)
        {
            if (c.IsEmpty)
            {
                return(NullPacket(PacketTypes.ColorId));
            }
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.ColorId;
            packet.Add(c.A);
            packet.Add(c.R);
            packet.Add(c.G);
            packet.Add(c.B);
            return(packet);
        }
Пример #24
0
        /// <summary>
        /// Serialize an Int64
        /// </summary>
        /// <param name="i">The Int64</param>
        /// <returns>The Packet</returns>
        public static SerializedPacket SerializeInt64(Int64 i)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.Integer64Id;
            packet.Add((byte)((i >> 0) & 0xFF));
            packet.Add((byte)((i >> 8) & 0xFF));
            packet.Add((byte)((i >> 16) & 0xFF));
            packet.Add((byte)((i >> 24) & 0xFF));
            packet.Add((byte)((i >> 32) & 0xFF));
            packet.Add((byte)((i >> 40) & 0xFF));
            packet.Add((byte)((i >> 48) & 0xFF));
            packet.Add((byte)((i >> 56) & 0xFF));
            return(packet);
        }
Пример #25
0
        /// <summary>
        /// Deserialize an IPEndPoint
        /// </summary>
        /// <param name="s">The packet</param>
        /// <returns>The end point</returns>
        public static System.Net.IPEndPoint DeserializeIPEndPoint(SerializedPacket s)
        {
            VerifyPacket(s, PacketTypes.IPEndPointId);
            if (s.Data.Count != 3)
            {
                throw new Exception("Incorrect Data Length");
            }
            System.Net.Sockets.AddressFamily family = (System.Net.Sockets.AddressFamily)DeserializeInt((SerializedPacket)s.Data[0]);
            int port = DeserializeInt((SerializedPacket)s.Data[1]);

//            long scopeId = DeserializeLong( (SerializedPacket)s.Data[2] );
            byte[] addr = DeserializeByteArray((SerializedPacket)s.Data[2]);
//            return new System.Net.IPEndPoint( new System.Net.IPAddress( addr, scopeId ), port );
            return(new System.Net.IPEndPoint(new System.Net.IPAddress(addr), port));
        }
Пример #26
0
        /// <summary>
        /// Serialize a ULong
        /// </summary>
        /// <param name="i">The ULong</param>
        /// <returns>The Packet</returns>
        public static SerializedPacket SerializeULong(ulong i)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.ULongId;
            packet.Add((byte)((i >> 0) & 0xFF));
            packet.Add((byte)((i >> 8) & 0xFF));
            packet.Add((byte)((i >> 16) & 0xFF));
            packet.Add((byte)((i >> 24) & 0xFF));
            packet.Add((byte)((i >> 32) & 0xFF));
            packet.Add((byte)((i >> 40) & 0xFF));
            packet.Add((byte)((i >> 48) & 0xFF));
            packet.Add((byte)((i >> 56) & 0xFF));
            return(packet);
        }
Пример #27
0
 /// <summary>
 /// Deserialize a ULong
 /// </summary>
 /// <param name="s">The Packet</param>
 /// <returns>The ULong</returns>
 public static ulong DeserializeULong(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.ULongId);
     if (s.Data.Count != 8)
     {
         throw new Exception("Incorrect Data Length");
     }
     return((ulong)((((UInt64)((byte)s.Data[0]) << 0)) |
                    (((UInt64)((byte)s.Data[1]) << 8)) |
                    (((UInt64)((byte)s.Data[2]) << 16)) |
                    (((UInt64)((byte)s.Data[3]) << 24)) |
                    (((UInt64)((byte)s.Data[4]) << 32)) |
                    (((UInt64)((byte)s.Data[5]) << 40)) |
                    (((UInt64)((byte)s.Data[6]) << 48)) |
                    (((UInt64)((byte)s.Data[7]) << 56))));
 }
Пример #28
0
        /// <summary>
        /// Serialize an IntArray
        /// </summary>
        /// <param name="i">The array</param>
        /// <returns>The Packet</returns>
        public static SerializedPacket SerializeIntArray(int[] i)
        {
            SerializedPacket packet = new SerializedPacket();

            packet.Type = PacketTypes.IntArrayId;
            ArrayList list = new ArrayList();

            foreach (int integer in i)
            {
                list.Add((byte)((integer >> 0) & 0xFF));
                list.Add((byte)((integer >> 8) & 0xFF));
                list.Add((byte)((integer >> 16) & 0xFF));
                list.Add((byte)((integer >> 24) & 0xFF));
            }
            packet.Data.AddRange((byte[])list.ToArray(typeof(byte)));
            return(packet);
        }
Пример #29
0
 public QuickPollModel( SerializedPacket p )
 {
     SerializedPacket.VerifyPacket( p, this.GetClassId() );
     this.m_Id = SerializedPacket.DeserializeGuid( p.GetNextPart() );
     this.m_OriginalSlideId = SerializedPacket.DeserializeGuid( p.GetNextPart() );
     this.m_QuickPollStyle = (QuickPollStyle)SerializedPacket.DeserializeInt( p.GetNextPart() );
     this.m_Changed = SerializedPacket.DeserializeBool( p.GetNextPart() );
     this.m_Choices = new string[SerializedPacket.DeserializeInt( p.GetNextPart() )];
     for( int i = 0; i < this.m_Choices.Length; i++ ) {
         this.m_Choices[i] = SerializedPacket.DeserializeString( p.GetNextPart() );
     }
     int cnt = SerializedPacket.DeserializeInt( p.GetNextPart() );
     this.m_QuickPollResults = new QuickPollResultCollection( this, "QuickPollResults" );
     for( int j = 0; j < cnt; j++ ) {
         this.AddResult( new QuickPollResultModel( p.GetNextPart() ) );
     }
 }
Пример #30
0
 public LocalId( SerializedPacket p )
 {
     SerializedPacket.VerifyPacket( p, this.GetClassId() );
 }
Пример #31
0
 /// <summary>
 /// Serialize a Color struct
 /// </summary>
 /// <param name="c">The color</param>
 /// <returns>The packet</returns>
 public static SerializedPacket SerializeColor( System.Drawing.Color c )
 {
     if( c.IsEmpty ) return NullPacket( PacketTypes.ColorId );
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.ColorId;
     packet.Add( c.A );
     packet.Add( c.R );
     packet.Add( c.G );
     packet.Add( c.B );
     return packet;
 }
Пример #32
0
 /// <summary>
 /// Serialize a ULong
 /// </summary>
 /// <param name="i">The ULong</param>
 /// <returns>The Packet</returns>
 public static SerializedPacket SerializeULong( ulong i )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.ULongId;
     packet.Add( (byte)((i >> 0) & 0xFF) );
     packet.Add( (byte)((i >> 8) & 0xFF) );
     packet.Add( (byte)((i >> 16) & 0xFF) );
     packet.Add( (byte)((i >> 24) & 0xFF) );
     packet.Add( (byte)((i >> 32) & 0xFF) );
     packet.Add( (byte)((i >> 40) & 0xFF) );
     packet.Add( (byte)((i >> 48) & 0xFF) );
     packet.Add( (byte)((i >> 56) & 0xFF) );
     return packet;
 }
Пример #33
0
 public void Add( SerializedPacket p )
 {
     if( this.NumChildren == -1 && this.Data.Count != 0 )
         throw new Exception( "Can't Add Both Binary and Object Data" );
     this.Data.Add( p );
     this.NumChildren = this.Data.Count;
     this.CachedSize = -1;
 }
Пример #34
0
 /// <summary>
 /// Serialize an IPEndPoint
 /// </summary>
 /// <param name="ep">The end point</param>
 /// <returns>The packet</returns>
 public static SerializedPacket SerializeIPEndPoint( System.Net.IPEndPoint ep )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.IPEndPointId;
     // Pack the Data
     packet.Add( SerializeInt( (int)ep.AddressFamily ) );
     packet.Add( SerializeInt( ep.Port ) );
     //            packet.Add( SerializeLong( ep.Address.ScopeId ) );
     packet.Add( SerializeByteArray( ep.Address.GetAddressBytes() ) );
     return packet;
 }
Пример #35
0
 /// <summary>
 /// Serialize a Rectangle
 /// </summary>
 /// <param name="r">The rectangle</param>
 /// <returns>The packet</returns>
 public static SerializedPacket SerializeRectangle( System.Drawing.Rectangle r )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.RectangleId;
     packet.Add( SerializeInt( r.X ) );
     packet.Add( SerializeInt( r.Y ) );
     packet.Add( SerializeInt( r.Width ) );
     packet.Add( SerializeInt( r.Height ) );
     return packet;
 }
Пример #36
0
 /// <summary>
 /// Deserialize a String
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The string</returns>
 public static string DeserializeString( SerializedPacket s )
 {
     VerifyPacket( s, PacketTypes.StringId );
     if( s.Type < 0 ) return null;
     return System.Text.Encoding.ASCII.GetString( (byte[])s.Data.ToArray( typeof(byte) ) );
 }
Пример #37
0
 /// <summary>
 /// Serialize an Int64
 /// </summary>
 /// <param name="i">The Int64</param>
 /// <returns>The Packet</returns>
 public static SerializedPacket SerializeInt64( Int64 i )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.Integer64Id;
     packet.Add( (byte)((i >> 0) & 0xFF) );
     packet.Add( (byte)((i >> 8) & 0xFF) );
     packet.Add( (byte)((i >> 16) & 0xFF) );
     packet.Add( (byte)((i >> 24) & 0xFF) );
     packet.Add( (byte)((i >> 32) & 0xFF) );
     packet.Add( (byte)((i >> 40) & 0xFF) );
     packet.Add( (byte)((i >> 48) & 0xFF) );
     packet.Add( (byte)((i >> 56) & 0xFF) );
     return packet;
 }
Пример #38
0
 /// <summary>
 /// Deserialize a GUID
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The guid</returns>
 public static Guid DeserializeMD5(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.ByteArrayClassId);
     if (s.Data.Count != 16)
         throw new Exception("Incorrect Data Length");
     return new Guid((byte[])s.Data.ToArray(typeof(byte)));
 }
Пример #39
0
 /// <summary>
 /// Deserialize a Rectangle
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The rectangle</returns>
 public static System.Drawing.Rectangle DeserializeRectangle( SerializedPacket s )
 {
     VerifyPacket( s, PacketTypes.RectangleId );
     if( s.Data.Count != 4 )
         throw new Exception( "Incorrect Data Length" );
     return new System.Drawing.Rectangle( DeserializeInt( (SerializedPacket)s.Data[0] ),
                                          DeserializeInt( (SerializedPacket)s.Data[1] ),
                                          DeserializeInt( (SerializedPacket)s.Data[2] ),
                                          DeserializeInt( (SerializedPacket)s.Data[3] ) );
 }
Пример #40
0
 /// <summary>
 /// Deserialize an IPEndPoint
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The end point</returns>
 public static System.Net.IPEndPoint DeserializeIPEndPoint( SerializedPacket s )
 {
     VerifyPacket( s, PacketTypes.IPEndPointId );
     if( s.Data.Count != 3 )
         throw new Exception( "Incorrect Data Length" );
     System.Net.Sockets.AddressFamily family = (System.Net.Sockets.AddressFamily) DeserializeInt( (SerializedPacket)s.Data[0] );
     int port = DeserializeInt( (SerializedPacket)s.Data[1] );
     //            long scopeId = DeserializeLong( (SerializedPacket)s.Data[2] );
     byte[] addr = DeserializeByteArray( (SerializedPacket)s.Data[2] );
     //            return new System.Net.IPEndPoint( new System.Net.IPAddress( addr, scopeId ), port );
     return new System.Net.IPEndPoint( new System.Net.IPAddress( addr ), port );
 }
Пример #41
0
 /// <summary>
 /// Deserialize a Float
 /// </summary>
 /// <param name="s">The packet</param>
 /// <returns>The float</returns>
 public static float DeserializeFloat(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.FloatId);
     return(BitConverter.ToSingle((byte[])s.Data.ToArray(typeof(byte)), 0));
 }
Пример #42
0
 public DeckInformationMessage( Message parent, SerializedPacket p )
     : base(parent, p)
 {
 }
Пример #43
0
 /// <summary>
 /// Serialize a Float
 /// </summary>
 /// <param name="f">The float</param>
 /// <returns>The Packet</returns>
 public static SerializedPacket SerializeFloat( float f )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.FloatId;
     packet.Add( BitConverter.GetBytes( f ) );
     return packet;
 }
Пример #44
0
 /// <summary>
 /// Deserialize a ULong
 /// </summary>
 /// <param name="s">The Packet</param>
 /// <returns>The ULong</returns>
 public static ulong DeserializeULong( SerializedPacket s )
 {
     VerifyPacket( s, PacketTypes.ULongId );
     if( s.Data.Count != 8 )
         throw new Exception( "Incorrect Data Length" );
     return (ulong)( (((UInt64)((byte)s.Data[0]) << 0 )) |
                     (((UInt64)((byte)s.Data[1]) << 8 )) |
                     (((UInt64)((byte)s.Data[2]) << 16)) |
                     (((UInt64)((byte)s.Data[3]) << 24)) |
                     (((UInt64)((byte)s.Data[4]) << 32)) |
                     (((UInt64)((byte)s.Data[5]) << 40)) |
                     (((UInt64)((byte)s.Data[6]) << 48)) |
                     (((UInt64)((byte)s.Data[7]) << 56)));
 }
Пример #45
0
 /// <summary>
 /// Serialize an Int32
 /// </summary>
 /// <param name="i">The Int</param>
 /// <returns>The Packet</returns>
 public static SerializedPacket SerializeInt( int i )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.Integer32Id;
     packet.Add( (byte)((i >> 0) & 0xFF) );
     packet.Add( (byte)((i >> 8) & 0xFF) );
     packet.Add( (byte)((i >> 16) & 0xFF) );
     packet.Add( (byte)((i >> 24) & 0xFF) );
     return packet;
 }
Пример #46
0
 public static bool IsNullPacket( SerializedPacket p )
 {
     return ( p.Type < 0 ) ? true : false;
 }
Пример #47
0
 /// <summary>
 /// Serialize an IntArray
 /// </summary>
 /// <param name="i">The array</param>
 /// <returns>The Packet</returns>
 public static SerializedPacket SerializeIntArray( int[] i )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.IntArrayId;
     ArrayList list = new ArrayList();
     foreach( int integer in i ) {
         list.Add( (byte)((integer >> 0) & 0xFF) );
         list.Add( (byte)((integer >> 8) & 0xFF) );
         list.Add( (byte)((integer >> 16) & 0xFF) );
         list.Add( (byte)((integer >> 24) & 0xFF) );
     }
     packet.Data.AddRange( (byte[])list.ToArray( typeof(byte) ) );
     return packet;
 }
Пример #48
0
 public static SerializedPacket NullPacket( int type )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = -type;
     return packet;
 }
Пример #49
0
 /// <summary>
 /// Serialize a GUID
 /// </summary>
 /// <param name="g">The guid</param>
 /// <returns>The packet</returns>
 public static SerializedPacket SerializeMD5(Guid g)
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.ByteArrayClassId;
     packet.Add(g.ToByteArray());
     return packet;
 }
Пример #50
0
 /// <summary>
 /// Serialize a Boolean Value
 /// </summary>
 /// <param name="i"></param>
 /// <returns></returns>
 public static SerializedPacket SerializeBool( bool i )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.BoolId;
     packet.Add( (i) ? (byte)1 : (byte)0 );
     return packet;
 }
Пример #51
0
 /// <summary>
 /// Serialize a String
 /// </summary>
 /// <param name="s">The string</param>
 /// <returns>The packet</returns>
 public static SerializedPacket SerializeString( string s )
 {
     if( s == null ) return NullPacket( PacketTypes.StringId );
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.StringId;
     packet.Data.AddRange( System.Text.Encoding.ASCII.GetBytes( s ) );
     return packet;
 }
Пример #52
0
 /// <summary>
 /// Serialize a Byte Value
 /// </summary>
 /// <param name="i">The Byte</param>
 /// <returns>The Packet</returns>
 public static SerializedPacket SerializeByte( byte i )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.ByteId;
     packet.Data.Add( i );
     return packet;
 }
Пример #53
0
 /// <summary>
 /// Verify that the given SerializedPacket is of the given type
 /// </summary>
 /// <param name="s">The packet</param>
 /// <param name="type">The type to check for</param>
 public static void VerifyPacket( SerializedPacket s, int type )
 {
     if( s.Type != type && s.Type != -type ) {
         throw new Exception( "This packet type is not appropriate for this function" );
     }
 }
Пример #54
0
 /// <summary>
 /// Serialize a ByteArray
 /// </summary>
 /// <param name="i">The array</param>
 /// <returns>The Packet</returns>
 public static SerializedPacket SerializeByteArray( byte[] i )
 {
     SerializedPacket packet = new SerializedPacket();
     packet.Type = PacketTypes.ByteArrayId;
     packet.Data.AddRange( i );
     return packet;
 }
Пример #55
0
 /// <summary>
 /// Deserialize a Boolean Value
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public static bool DeserializeBool( SerializedPacket s )
 {
     VerifyPacket( s, PacketTypes.BoolId );
     if( s.Data.Count != 1 )
         throw new Exception( "Incorrect Data Length" );
     return ((byte)s.Data[0] == 1) ? true : false;
 }
Пример #56
0
 /// <summary>
 /// Deserialize a ByteArray
 /// </summary>
 /// <param name="s">The Packet</param>
 /// <returns>The array</returns>
 public static byte[] DeserializeByteArray(SerializedPacket s)
 {
     VerifyPacket(s, PacketTypes.ByteArrayId);
     return((byte[])s.Data.ToArray(typeof(byte)));
 }
Пример #57
0
 public SerializedPacket Serialize()
 {
     SerializedPacket p = new SerializedPacket( this.GetClassId() );
     return p;
 }
Пример #58
0
 /// <summary>
 /// Deserialize a ByteArray
 /// </summary>
 /// <param name="s">The Packet</param>
 /// <returns>The array</returns>
 public static int[] DeserializeIntArray( SerializedPacket s )
 {
     VerifyPacket( s, PacketTypes.IntArrayId );
     ArrayList list = new ArrayList();
     for( int i = 0; i < s.Data.Count; i+=4 ) {
         list.Add( (int)( ((byte)s.Data[i + 0] << 0 ) |
                          ((byte)s.Data[i + 1] << 8 ) |
                          ((byte)s.Data[i + 2] << 16) |
                          ((byte)s.Data[i + 3] << 24)) );
     }
     return (int[])list.ToArray( typeof(int) );
 }
Пример #59
0
        public static IGenericSerializable DecodeMessage(Messages.Message parent, SerializedPacket p)
        {
            switch (p.Type)
            {
            case MessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case GroupInformationMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case ParticipantGroupAddedMessageId:
                return(new Messages.Network.ParticipantGroupAddedMessage(parent, p));

            case ParticipantGroupRemovedMessageId:
                return(new Messages.Network.ParticipantGroupRemovedMessage(parent, p));

            case RoleMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case InstructorMessageId:
                return(new Messages.Network.InstructorMessage(parent, p));

            case StudentMessageId:
                return(new Messages.Network.StudentMessage(parent, p));

            case PublicMessageId:
                return(new Messages.Network.PublicMessage(parent, p));

            case PresentationMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case InstructorCurrentPresentationChangedMessageId:
                return(new Messages.Network.InstructorCurrentPresentationChangedMessage(parent, p));

            case PresentationInformationMessageId:
                return(new Messages.Presentation.PresentationInformationMessage(parent, p));

            case PresentationEndedMessageId:
                return(new Messages.Presentation.PresentationEndedMessage(parent, p));

            case DeckTraversalMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case InstructorCurrentDeckTraversalChangedMessageId:
                return(new Messages.Network.InstructorCurrentDeckTraversalChangedMessage(parent, p));

            case SlideDeckTraversalMessageId:
                return(new Messages.Presentation.SlideDeckTraversalMessage(parent, p));

            case DeckTraversalRemovedFromPresentationMessageId:
                return(new Messages.Presentation.DeckTraversalRemovedFromPresentationMessage(parent, p));

            case ExecuteScriptMessageId:
                return(new Messages.ExecuteScriptMessage(parent, p));

            case SynchronizationMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case SyncBeginMessageId:
                return(new Messages.SyncBeginMessage(parent, p));

            case SyncPingMessageId:
                return(new Messages.SyncPingMessage(parent, p));

            case SyncPongMessageId:
                return(new Messages.SyncPongMessage(parent, p));

            case DeckMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case DeckInformationMessageId:
                return(new Messages.Presentation.DeckInformationMessage(parent, p));

            case SheetMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case SheetRemovedMessageId:
                return(new Messages.Presentation.SheetRemovedMessage(parent, p));

            case ImageSheetMessageId:
                return(new Messages.Presentation.ImageSheetMessage(parent, p));

            case TextSheetMessageId:
                return(new Messages.Presentation.TextSheetMessage(parent, p));

            case InkSheetMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case InkSheetInformationMessageId:
                return(new Messages.Presentation.InkSheetInformationMessage(parent, p));

            case InkSheetStrokesAddedMessageId:
                return(new Messages.Presentation.InkSheetStrokesAddedMessage(parent, p));

            case InkSheetStrokesDeletingMessageId:
                return(new Messages.Presentation.InkSheetStrokesDeletingMessage(parent, p));

            case RealTimeInkSheetMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case RealTimeInkSheetInformationMessageId:
                return(new Messages.Presentation.RealTimeInkSheetInformationMessage(parent, p));

            case RealTimeInkSheetDataMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case RealTimeInkSheetPacketsMessageId:
                return(new Messages.Presentation.RealTimeInkSheetPacketsMessage(parent, p));

            case RealTimeInkSheetStylusUpMessageId:
                return(new Messages.Presentation.RealTimeInkSheetStylusUpMessage(parent, p));

            case RealTimeInkSheetStylusDownMessageId:
                return(new Messages.Presentation.RealTimeInkSheetStylusDownMessage(parent, p));

            case SlideMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case SlideInformationMessageId:
                return(new Messages.Presentation.SlideInformationMessage(parent, p));

            case SlideDeletedMessageId:
                return(new Messages.Presentation.SlideDeletedMessage(parent, p));

            case StudentSubmissionSlideMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case StudentSubmissionSlideInformationMessageId:
                return(new Messages.Presentation.StudentSubmissionSlideInformationMessage(parent, p));

            case SubmissionStatusMessageId:
                return(new Messages.Presentation.SubmissionStatusMessage(parent, p));

            case TableOfContentsEntryMessageId:
                return(new Messages.Presentation.TableOfContentsEntryMessage(parent, p));

            case TableOfContentsEntryRemovedMessageId:
                return(new Messages.Presentation.TableOfContentsEntryRemovedMessage(parent, p));

            case DeckSlideContentMessageId:
                return(new Messages.Presentation.DeckSlideContentMessage(parent, p));

            case BroadcastMessageId:
                return(new Broadcast.BroadcastMessage(p));

            case ChunkId:
                return(new Chunking.Chunk(p));

            case TCPHandshakeMessageId:
                return(new TCP.TCPHandshakeMessage(p));

            case TCPHeartbeatMessageId:
                return(new TCP.TCPHeartbeatMessage(p));

            case VersionRequestMessageId:
                return(new Messages.Network.VersionRequestMessage(parent, p));

            case VersionResponseMessageId:
                return(new Messages.Network.VersionResponseMessage(parent, p));

            case QuickPollMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case QuickPollInformationMessageId:
                return(new Messages.Presentation.QuickPollInformationMessage(parent, p));

            case QuickPollResultMessageId:
                throw new Exception("Cannot deserialize an abstract class!");

            case QuickPollResultInformationMessageId:
                return(new Messages.Presentation.QuickPollResultInformationMessage(parent, p));

            case QuickPollResultRemovedMessageId:
                return(new Messages.Presentation.QuickPollResultRemovedMessage(parent, p));

            case QuickPollSheetMessageId:
                return(new Messages.Presentation.QuickPollSheetMessage(parent, p));

            default:
                throw new Exception("Unknown Packet ID: " + p.Type);
            }
        }
Пример #60
0
 public static bool IsNullPacket(SerializedPacket p)
 {
     return((p.Type < 0) ? true : false);
 }