- protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) {
- while (msg.readableBytes() > chunkSize) {
- ByteBuf chunk = Unpooled.buffer(chunkSize);
- chunk.writeBytes(createChunkHeader(chunkSize));
- chunk.writeBytes(msg.readBytes(chunkSize));
- ctx.write(chunk);
- }
- out.writeBytes(createChunkHeader(msg.readableBytes()));
- out.writeBytes(msg.readBytes(msg.readableBytes()));
- out.writeBytes(NetconfMessageConstants.END_OF_CHUNK);
- }
+ protected void encode(final ChannelHandlerContext ctx, final ByteBuf msg, final ByteBuf out) {
+ do {
+ final int xfer = Math.min(chunkSize, msg.readableBytes());
+
+ out.writeBytes(NetconfMessageConstants.START_OF_CHUNK);
+ out.writeBytes(String.valueOf(xfer).getBytes(Charsets.US_ASCII));
+ out.writeByte('\n');