local json = require "cjson"
local netpack_base = require "skynet-fly.netpack.netpack_base"

local pcall = pcall
local assert = assert

local M = {}

--------------------------------------------------------------------------
--按包名方式编码
--------------------------------------------------------------------------
function M.encode(_,body)
	assert(body)
	return pcall(json.encode,body)
end
--------------------------------------------------------------------------
--按包名方式解码
--------------------------------------------------------------------------
function M.decode(_,pstr)
	assert(pstr)
	return pcall(json.decode,pstr)
end

--------------------------------------------------------------------------
--按包名方式打包
--------------------------------------------------------------------------
M.pack = netpack_base.create_pack(M.encode)

--------------------------------------------------------------------------
--按包名方式解包
--------------------------------------------------------------------------
M.unpack = netpack_base.create_unpack(M.decode)

--------------------------------------------------------------------------
--按协议号方式打包
--------------------------------------------------------------------------
M.pack_by_id = netpack_base.create_pack_by_id(M.encode)
--------------------------------------------------------------------------
--按协议号方式解包
--------------------------------------------------------------------------
M.unpack_by_id = netpack_base.create_unpack_by_id(M.decode)

return M