public void writeBytes(ByteBuf buf) { int maxSize = getCapacity() - writerIndex; int remainBytes = buf.remainBytes(); if (remainBytes < maxSize) { maxSize = remainBytes; } writeBytes(buf.getBuffer(), buf.getReaderIndex(), maxSize); buf.skipReaderIndex(maxSize); }
public void writeBytes(ByteBuf buf, int maxSize) { if (buf.remainBytes() > maxSize) { writeBytes(buf.getBuffer(), buf.getReaderIndex(), maxSize); buf.skipReaderIndex(maxSize); } else { writeBytes(buf); } }
public override void read(ConnectionHandlerContext ctx, object msg) { ByteBuf buf = (ByteBuf)msg; //System.Console.WriteLine("receive bytes " + buf.remainBytes()); MemoryStream ms = new MemoryStream(buf.getBuffer(), buf.getReaderIndex(), buf.remainBytes()); T obj = ProtoBuf.Serializer.Deserialize <T>(ms); buf.skipReaderIndex((int)ms.Position); if (receiveObjFunc != null) { receiveObjFunc(obj); } }