erlang自定义二进制协议
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 rivejä
633 B

  1. function test()
  2. -- 封包
  3. local msgTable = new phoneNumber()
  4. msgTable.number = new test()
  5. msgTable.type = 1
  6. local byteArray = ByteArray()
  7. byteArray = msgTable.build(byteArray)
  8. local body = byteArray.getBytes()
  9. -- 包头(大小端转换后的包体长度)
  10. local bodyLength = string.len(body) -- 包体长度
  11. local head = string.pack(">I4", bodyLength) -- 包头四个字节,这里要用"i"
  12. -- 发送
  13. local nSend = dosend(head..body)
  14. -- 解包 先读取消息id 根据消息id到protoNane.lua 获取函数名
  15. -- 再根据函数名到 _G表找到反序列化的函数
  16. end