Comments (4)
参考netpack_base.create_unpack 解析即可,不过要注意传入进来的msgbuff是剔除掉2字节了
from skynet_fly.
刚刚找到了。。。。
function M.create_pack(encode)
return function(name, tab)
assert(name)
assert(tab)
local ok, str = encode(name, tab)
if not ok then
return nil, str
end
local pbmsgbuff = spack(">I2", name:len()) .. name .. str
log.info("name:", name)
log.info("str:", str)
log.info("pbmsgbuff:", pbmsgbuff)
return pbmsgbuff
end
end
function M.create_unpack(decode)
return function(msgbuff)
assert(msgbuff)
local name_sz = (msgbuff:byte(1) << 8) + msgbuff:byte(2)
local packname = msgbuff:sub(3, 3 + name_sz - 1)
local pack_str = msgbuff:sub(3 + name_sz)
log.info("name_sz:", name_sz)
log.info("packname:", packname)
log.info("pack_str:", pack_str)
local ok, tab = decode(packname, pack_str)
if not ok then
return nil, tab
end
return packname, tab
end
end
from skynet_fly.
在 util_net_base 可以看见,其中gate的解析没有拆分出2字节是因为skynet已经做了,ws_gate的解析可以看见有剔除掉2字节的包长度表示再传入具体的unpack
from skynet_fly.
谢谢大佬 :)
from skynet_fly.
Related Issues (9)
- 如何调整util_net_base.lua HOT 1
- 常驻的table如何热更 HOT 1
- 在阿里云机器上启动报错了 HOT 24
- Is it possible to use lua-radix-router to get the best performance? HOT 11
- make build fail due to luaclib/lfs.so HOT 6
- 这个支持多台机器分布式部署吗 HOT 3
- 在游戏中使用redisf会报错 HOT 1
- json插件如何正确使用 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from skynet_fly.