public virtual bool equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            ControlPacket other = (ControlPacket)obj;

            if (controlPacketType != other.controlPacketType)
            {
                return(false);
            }
            if (destinationID != other.destinationID)
            {
                return(false);
            }
            if (timeStamp != other.timeStamp)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        /**
         * create the right type of control packet based on the packet data
         * @param packetData
         * @return
         */
        public static ControlPacket createControlPacket(byte[] encodedData, int length)
        {
            ControlPacket packet = null;

            int  pktType        = PacketUtil.decodeType(encodedData, 0);
            long additionalInfo = PacketUtil.decode(encodedData, 4);
            long timeStamp      = PacketUtil.decode(encodedData, 8);
            long destID         = PacketUtil.decode(encodedData, 12);

            byte[] controlInformation = new byte[length - 16];
            Array.Copy(encodedData, 16, controlInformation, 0, controlInformation.Length);

            //TYPE 0000:0
            if ((int)ControlPacket.ControlPacketType.CONNECTION_HANDSHAKE == pktType)
            {
                packet = new ConnectionHandshake(controlInformation);
            }
            //TYPE 0001:1
            else if ((int)ControlPacket.ControlPacketType.KEEP_ALIVE == pktType)
            {
                packet = new KeepAlive();
            }
            //TYPE 0010:2
            else if ((int)ControlPacket.ControlPacketType.ACK == pktType)
            {
                packet = new Acknowledgement(additionalInfo, controlInformation);
            }
            //TYPE 0011:3
            else if ((int)ControlPacket.ControlPacketType.NAK == pktType)
            {
                packet = new NegativeAcknowledgement(controlInformation);
            }
            //TYPE 0101:5
            else if ((int)ControlPacket.ControlPacketType.SHUTDOWN == pktType)
            {
                packet = new Shutdown();
            }
            //TYPE 0110:6
            else if ((int)ControlPacket.ControlPacketType.ACK2 == pktType)
            {
                packet = new Acknowledgment2(additionalInfo, controlInformation);
            }
            //TYPE 0111:7
            else if ((int)ControlPacket.ControlPacketType.MESSAGE_DROP_REQUEST == pktType)
            {
                packet = new MessageDropRequest(controlInformation);
            }
            //TYPE 1111:8
            else if ((int)ControlPacket.ControlPacketType.USER_DEFINED == pktType)
            {
                packet = new UserDefined(controlInformation);
            }

            if (packet != null)
            {
                packet.setTimeStamp(timeStamp);
                packet.setDestinationID(destID);
            }
            return(packet);
        }