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; }
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; }
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; }
// 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; }
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; }
public void PacketBufferTest1() { PacketBuffer buffer = new PacketBuffer(); buffer.Dispose(); try { buffer.Write(1); } catch (Exception) { return; } throw new Exception("Ssibal"); }
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; }
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"); } }
public object Decode(IChannel channel, PacketBuffer buffer) { var data = new byte[buffer.AvailableBytes()]; buffer.ReadBytes(data); return data; }
public object Decode(IChannel channel, PacketBuffer buffer) { var data = new byte[buffer.AvailableBytes()]; // 버퍼에 남아 있는 사이즈 만큼 byte 배열 할당 buffer.ReadBytes(data); // 버퍼에서 byte[]를 읽어옴 return data; }