288 Star 979 Fork 227

helyho / Voovan

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
LineMessageSplitter.java 743 Bytes
一键复制 编辑 原始数据 按行查看 历史
helyho 提交于 2021-01-11 17:54 . imp: 小优化
package org.voovan.network.messagesplitter;
import org.voovan.Global;
import org.voovan.network.IoSession;
import org.voovan.network.MessageSplitter;
import org.voovan.tools.buffer.TByteBuffer;
import java.nio.ByteBuffer;
/**
* 按换行对消息分割
*
* @author helyho
*
* Voovan Framework.
* WebSite: https://github.com/helyho/Voovan
* Licence: Apache v2 License
*/
public class LineMessageSplitter implements MessageSplitter {
public byte[] bytes = Global.STR_LF.getBytes();
@Override
public int canSplite(IoSession session, ByteBuffer byteBuffer) {
if(byteBuffer.limit() > 1){
int lineBreakIndex = TByteBuffer.indexOf(byteBuffer, bytes);
if(lineBreakIndex >=0 )
return lineBreakIndex+1;
}
return -1;
}
}
Java
1
https://gitee.com/helyho/Voovan.git
git@gitee.com:helyho/Voovan.git
helyho
Voovan
Voovan
master

搜索帮助