Inheritance: IDisposable
コード例 #1
0
        public dynamic Decode(IChannel channel, PacketBuffer buffer)
        {
            buffer.BeginBufferIndex();
            if (buffer.AvailableBytes() < 1)
            {
                buffer.ResetBufferIndex();
                return null;
            }

            var data = new byte[buffer.AvailableBytes()];
            buffer.ReadBytes(data);

            string s = System.Text.Encoding.UTF8.GetString(data);
            int len = s.IndexOf('\n');
            if (len == -1)
            {
                buffer.ResetBufferIndex();
                return null;
            }
            s = s.Substring(0, len + 1);

            buffer.SetPosition(System.Text.Encoding.UTF8.GetByteCount(s));
            buffer.EndBufferIndex();

            return s;
        }
コード例 #2
0
ファイル: PacketEncoder.cs プロジェクト: shlee322/Netronics
 public PacketBuffer Encode(IChannel channel, object data)
 {
     var bytes = data as byte[];
     if (bytes == null)
         return null;
     var buffer = new PacketBuffer();
     buffer.Write(bytes, 0, bytes.Length);
     return buffer;
 }
コード例 #3
0
        public PacketBuffer Encode(IChannel channel, dynamic data)
        {
            if (data.GetType() != typeof(string))
                return null;

            byte[] bytes = data;
            PacketBuffer buffer = new PacketBuffer();
            buffer.Write(bytes, 0, bytes.Length);
            return buffer;
        }
コード例 #4
0
ファイル: PacketEncoder.cs プロジェクト: shlee322/Netronics
        // SendMessage로 보낸 메시지를 PacketBuffer형태로 변환합니다.
        public PacketBuffer Encode(IChannel channel, object data)
        {
            if (data.GetType() != typeof(byte[])) // 보내는 메시지가 byte[]가 아닐 경우 전송 취소
                return null;

            var bytes = (byte[]) data;
            var buffer = new PacketBuffer();
            buffer.Write(bytes, 0, bytes.Length); // Buffer에 bytes를 쓴다.
            return buffer;
        }
コード例 #5
0
        public PacketBuffer Encode(IChannel channel, dynamic data)
        {
            if (data.GetType() != typeof(string))
                return null;

            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
            PacketBuffer buffer = new PacketBuffer();
            buffer.WriteUInt32((uint)bytes.Length);
            buffer.Write(bytes, 0, bytes.Length);
            return buffer;
        }
コード例 #6
0
        public void PacketBufferTest1()
        {
            PacketBuffer buffer = new PacketBuffer();
            buffer.Dispose();
            try
            {

                buffer.Write(1);
            }
            catch (Exception) { return; }
            throw new Exception("Ssibal");
        }
コード例 #7
0
        public dynamic Decode(IChannel channel, PacketBuffer buffer)
        {
            buffer.BeginBufferIndex();
            if (buffer.AvailableBytes() < 1)
            {
                buffer.ResetBufferIndex();
                return null;
            }

            var data = new byte[buffer.AvailableBytes()];
            buffer.ReadBytes(data);
            buffer.EndBufferIndex();
            return data;
        }
コード例 #8
0
        public void PacketBufferTest2()
        {
            PacketBuffer buffer = new PacketBuffer();
            buffer.Write(1);
            buffer.Write(0);
            buffer.Write(0);
            buffer.Write(5);

            buffer.BeginBufferIndex();
            uint m = 0;
            for (int i = 0; i < 4; i++)
                m += buffer.ReadUInt32();
            if (m != 6) { throw new Exception("PacketBuffer unji"); }
        }
コード例 #9
0
ファイル: PacketEncoder.cs プロジェクト: shlee322/Netronics
 public object Decode(IChannel channel, PacketBuffer buffer)
 {
     var data = new byte[buffer.AvailableBytes()];
     buffer.ReadBytes(data);
     return data;
 }
コード例 #10
0
ファイル: PacketEncoder.cs プロジェクト: shlee322/Netronics
 public object Decode(IChannel channel, PacketBuffer buffer)
 {
     var data = new byte[buffer.AvailableBytes()]; // 버퍼에 남아 있는 사이즈 만큼 byte 배열 할당
     buffer.ReadBytes(data); // 버퍼에서 byte[]를 읽어옴
     return data;
 }