コード例 #1
0
ファイル: AriesPackets.cs プロジェクト: jwofles/ForkSO
 static AriesPackets()
 {
     ARIES_PACKET_BY_TYPEID = new Dictionary <uint, Type>();
     foreach (Type packetType in ARIES_PACKETS)
     {
         IAriesPacket packet = (IAriesPacket)Activator.CreateInstance(packetType);
         ARIES_PACKET_BY_TYPEID.Add(packet.GetPacketType().GetPacketCode(), packetType);
     }
 }
コード例 #2
0
        private void EncodeAries(IoSession session, object message, IProtocolEncoderOutput output)
        {
            IAriesPacket    ariesPacket     = (IAriesPacket)message;
            AriesPacketType ariesPacketType = ariesPacket.GetPacketType();

            var payload = IoBuffer.Allocate(128);

            payload.Order      = ByteOrder.LittleEndian;
            payload.AutoExpand = true;
            ariesPacket.Serialize(payload, Context);
            payload.Flip();

            int      payloadSize = payload.Remaining;
            IoBuffer headers     = IoBuffer.Allocate(12);

            headers.Order = ByteOrder.LittleEndian;

            /**
             * Aries header
             *  uint32	type
             *  uint32	timestamp
             *  uint32	payloadSize
             */
            uint timestamp = (uint)TimeSpan.FromTicks(DateTime.Now.Ticks - session.CreationTime.Ticks).TotalMilliseconds;

            headers.PutUInt32(ariesPacketType.GetPacketCode());
            headers.PutUInt32(timestamp);
            headers.PutUInt32((uint)payloadSize);

            if (payloadSize > 0)
            {
                headers.AutoExpand = true;
                headers.Put(payload);
            }

            headers.Flip();
            output.Write(headers);
            //output.Flush();
        }
コード例 #3
0
        public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
        {
            IVoltronPacket voltronPacket = writeRequest.OriginalRequest.Message as IVoltronPacket;

            if (voltronPacket != null)
            {
                var voltronBuffer = IoBuffer.Allocate(512);
                voltronBuffer.Order      = ByteOrder.BigEndian;
                voltronBuffer.AutoExpand = true;
                voltronPacket.Serialize(voltronBuffer, Context);
                voltronBuffer.Flip();

                var byteArray = new byte[voltronBuffer.Remaining];
                voltronBuffer.Get(byteArray, 0, voltronBuffer.Remaining);

                PacketLogger.OnPacket(new Packet
                {
                    Data      = byteArray,
                    Type      = PacketType.VOLTRON,
                    SubType   = voltronPacket.GetPacketType().GetPacketCode(),
                    Direction = PacketDirection.OUTPUT
                });
                nextFilter.MessageSent(session, writeRequest);
                return;
            }

            IAriesPacket ariesPacket = writeRequest.OriginalRequest.Message as IAriesPacket;

            if (ariesPacket != null)
            {
                IoBuffer ariesBuffer = IoBuffer.Allocate(128);
                ariesBuffer.AutoExpand = true;
                ariesBuffer.Order      = ByteOrder.LittleEndian;
                ariesPacket.Serialize(ariesBuffer, Context);
                ariesBuffer.Flip();

                var byteArray = new byte[ariesBuffer.Remaining];
                ariesBuffer.Get(byteArray, 0, ariesBuffer.Remaining);

                PacketLogger.OnPacket(new Packet
                {
                    Data      = byteArray,
                    Type      = PacketType.ARIES,
                    SubType   = ariesPacket.GetPacketType().GetPacketCode(),
                    Direction = PacketDirection.OUTPUT
                });
                nextFilter.MessageSent(session, writeRequest);
                return;
            }

            IoBuffer buffer = writeRequest.Message as IoBuffer;

            if (buffer == null)
            {
                nextFilter.MessageSent(session, writeRequest);
                return;
            }

            TryParseAriesFrame(buffer, PacketDirection.OUTPUT);
            nextFilter.MessageSent(session, writeRequest);
        }