java如何同时发送FileRegion和ChannelBuffer类型的数据包
public class Response{
public int packetLength;
public int cmd;
public int seqId;
public FileRegion fileRegion; //file content
public String filename;
public int begin;
public int end;
public String otherExtra;
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e){
if(e.getMessage() instanceof Request){
Request request = Request(e.getMessage());
Channel ch = e.getChannel();
Response response = new Response();
response.cmd = 111;
response.seqId = 111;
response.begin = 0;
response.end = 256;
response.fileRegion = new DefaultFileRegion(GetFile().getChannel(),response.begin, response.end);
response.filename = "test";
response.otherExtra = "service"
ch.write(response);
}
}
}
我需要使用零拷贝(os级别)来发送网络数据包字段中的数据。 netty在这两种类型的数据传输中支持FileRegion和ChannelBuffer。 但是现在我希望这两种类型的数据一起形成一个数据包
如何解决或如何编写上述编码编码器函数
# 1 楼答案
我想到了一种锁定频道的方法。写作时间。 这确保了传输的数据是连续的,当网络层、应用层传输的数据序列成为一个完整的网络数据包时
| 1111 |零拷贝数据| 2222 |
从应用层接收的数据
| 1111 | 45678 | 2222 |