1 Star 0 Fork 68

leavegee / cocosocket

forked from beykery / cocosocket 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LVProtocal.cpp 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
root 提交于 2014-01-26 17:47 . bug
/*
* File: LVProtocal.cpp
* Author: beykery
*
* Created on 2013年12月31日, 下午5:05
*/
#include "LVProtocal.h"
#include "ByteBuf.h"
#include <stddef.h>
LVProtocal::LVProtocal()
{
this->status = 0;
frame = NULL;
}
LVProtocal::~LVProtocal()
{
delete frame;
}
ByteBuf* LVProtocal::TranslateFrame(ByteBuf* in)
{
while (in->ReadableBytes() > 0)
{
switch (status)
{
case 0:
h = in->ReadByte();
status = 1;
break;
case 1:
l = in->ReadByte();
len = ((h << 8)&0x0000ff00) | (l);
frame = new ByteBuf(len + 2);
frame->WriteShort(len);
status = 2;
break;
case 2:
this->frame->WriteBytes(in);
if (frame->WritableBytes() <= 0)
{
status = 0;
return frame;
}
break;
}
}
return NULL;
}
1
https://gitee.com/leavegee/cocosocket.git
git@gitee.com:leavegee/cocosocket.git
leavegee
cocosocket
cocosocket
master

搜索帮助