Git Product home page Git Product logo

Comments (4)

huahua132 avatar huahua132 commented on July 29, 2024

参考netpack_base.create_unpack 解析即可,不过要注意传入进来的msgbuff是剔除掉2字节了

from skynet_fly.

bluesky0521 avatar bluesky0521 commented on July 29, 2024

刚刚找到了。。。。

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.

huahua132 avatar huahua132 commented on July 29, 2024

在 util_net_base 可以看见,其中gate的解析没有拆分出2字节是因为skynet已经做了,ws_gate的解析可以看见有剔除掉2字节的包长度表示再传入具体的unpack

from skynet_fly.

bluesky0521 avatar bluesky0521 commented on July 29, 2024

谢谢大佬 :)

from skynet_fly.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.