diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java index abd7ac49..ee66f031 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownArraySerializer.java @@ -56,6 +56,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeBooleanArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteBooleanArray({});", objectStr)).append(LS); break; @@ -74,6 +77,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeBooleanArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeBooleanArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteBooleanArray({});", objectStr)).append(LS); break; @@ -92,6 +98,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeByteArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteByteArray({});", objectStr)).append(LS); break; @@ -110,6 +119,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeByteArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeByteArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteByteArray({});", objectStr)).append(LS); break; @@ -128,6 +140,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeShortArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteShortArray({});", objectStr)).append(LS); break; @@ -146,6 +161,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeShortArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeShortArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteShortArray({});", objectStr)).append(LS); break; @@ -164,6 +182,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeIntArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteIntArray({});", objectStr)).append(LS); break; @@ -182,6 +203,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeIntArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeIntArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteIntArray({});", objectStr)).append(LS); break; @@ -200,6 +224,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeLongArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteLongArray({});", objectStr)).append(LS); break; @@ -218,6 +245,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeLongArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeLongArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteLongArray({});", objectStr)).append(LS); break; @@ -236,6 +266,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeFloatArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteFloatArray({});", objectStr)).append(LS); break; @@ -254,6 +287,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeFloatArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeFloatArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteFloatArray({});", objectStr)).append(LS); break; @@ -272,6 +308,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeDoubleArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteDoubleArray({});", objectStr)).append(LS); break; @@ -290,6 +329,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeDoubleArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeDoubleArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteDoubleArray({});", objectStr)).append(LS); break; @@ -308,6 +350,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeStringArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeStringArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteStringArray({});", objectStr)).append(LS); break; @@ -326,6 +371,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeCharArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeCharArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteCharArray({});", objectStr)).append(LS); break; @@ -344,6 +392,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writeCharArray({})", objectStr)).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writeCharArray({})", objectStr)).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WriteCharArray({});", objectStr)).append(LS); break; @@ -364,6 +415,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS); break; + case Lua: + builder.append(StringUtils.format("buffer:writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS); + break; case CSharp: builder.append(StringUtils.format("buffer.WritePacketArray<{}>({}, {});", EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId()), objectStr, objectProtocolField.getProtocolId())).append(LS); break; @@ -398,6 +452,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readBooleanArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray();", array)).append(LS); break; @@ -416,6 +473,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readBooleanArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readBooleanArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadBooleanArray();", array)).append(LS); break; @@ -434,6 +494,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readByteArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readByteArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadByteArray();", array)).append(LS); break; @@ -452,6 +515,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readByteArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readByteArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadByteArray();", array)).append(LS); break; @@ -470,6 +536,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readShortArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readShortArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadShortArray();", array)).append(LS); break; @@ -488,6 +557,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readShortArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readShortArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadShortArray();", array)).append(LS); break; @@ -506,6 +578,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readIntArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readIntArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadIntArray();", array)).append(LS); break; @@ -524,6 +599,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readIntArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readIntArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadIntArray();", array)).append(LS); break; @@ -542,6 +620,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readLongArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readLongArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadLongArray();", array)).append(LS); break; @@ -560,6 +641,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readLongArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readLongArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadLongArray();", array)).append(LS); break; @@ -578,6 +662,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readFloatArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readFloatArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadFloatArray();", array)).append(LS); break; @@ -596,6 +683,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readFloatArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readFloatArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadFloatArray();", array)).append(LS); break; @@ -614,6 +704,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readDoubleArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadDoubleArray();", array)).append(LS); break; @@ -632,6 +725,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readDoubleArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readDoubleArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadDoubleArray();", array)).append(LS); break; @@ -650,6 +746,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readStringArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readStringArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadStringArray();", array)).append(LS); break; @@ -668,6 +767,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readCharArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readCharArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadCharArray();", array)).append(LS); break; @@ -686,6 +788,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readCharArray()", array)).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readCharArray()", array)).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadCharArray();", array)).append(LS); break; @@ -704,6 +809,9 @@ public class CutDownArraySerializer implements ICutDownSerializer { case GdScript: builder.append(StringUtils.format("var {} = buffer.readPacketArray({})", array, objectProtocolField.getProtocolId())).append(LS); break; + case Lua: + builder.append(StringUtils.format("local {} = buffer:readPacketArray({})", array, objectProtocolField.getProtocolId())).append(LS); + break; case CSharp: builder.append(StringUtils.format("var {} = buffer.ReadPacketArray<{}>({});", array, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId()), objectProtocolField.getProtocolId())).append(LS); break; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java b/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java index 3d9bb17d..39e028f3 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/lua/GenerateLuaUtils.java @@ -243,14 +243,14 @@ public abstract class GenerateLuaUtils { var protocolClazzName = registration.getConstructor().getDeclaringClass().getSimpleName(); var luaBuilder = new StringBuilder(); - luaBuilder.append(StringUtils.format("function {}:write(byteBuffer, packet)", protocolClazzName)).append(LS); + luaBuilder.append(StringUtils.format("function {}:write(buffer, packet)", protocolClazzName)).append(LS); luaBuilder.append(TAB).append("if packet == null then").append(LS); - luaBuilder.append(TAB + TAB).append("byteBuffer:writeBoolean(false)").append(LS); + luaBuilder.append(TAB + TAB).append("buffer:writeBoolean(false)").append(LS); luaBuilder.append(TAB + TAB).append("return").append(LS); luaBuilder.append(TAB).append("end").append(LS); - luaBuilder.append(TAB).append("byteBuffer:writeBoolean(true)").append(LS); + luaBuilder.append(TAB).append("buffer:writeBoolean(true)").append(LS); for (var i = 0; i < fields.length; i++) { @@ -271,8 +271,8 @@ public abstract class GenerateLuaUtils { var protocolClazzName = registration.getConstructor().getDeclaringClass().getSimpleName(); var jsBuilder = new StringBuilder(); - jsBuilder.append(StringUtils.format("function {}:read(byteBuffer)", protocolClazzName)).append(LS); - jsBuilder.append(TAB).append("if not(byteBuffer:readBoolean()) then").append(LS); + jsBuilder.append(StringUtils.format("function {}:read(buffer)", protocolClazzName)).append(LS); + jsBuilder.append(TAB).append("if not(buffer:readBoolean()) then").append(LS); jsBuilder.append(TAB + TAB).append("return nil").append(LS); jsBuilder.append(TAB).append("end").append(LS); diff --git a/protocol/src/main/resources/lua/Buffer/ByteBuffer.lua b/protocol/src/main/resources/lua/Buffer/ByteBuffer.lua index 8d569932..abb2f513 100644 --- a/protocol/src/main/resources/lua/Buffer/ByteBuffer.lua +++ b/protocol/src/main/resources/lua/Buffer/ByteBuffer.lua @@ -5,6 +5,8 @@ --右移操作>>是无符号右移 --local Long = require("Long") +local ProtocolManager = require("LuaProtocol.ProtocolManager") + local maxInt = 2147483647 local minInt = -2147483648 local initSize = 128 @@ -33,6 +35,14 @@ function ByteBuffer:new() end +-- C#传进来的byte数组到lua里就会变成string +function readBytes(bytes) + local buffer = ByteBuffer:new() + buffer:writeBuffer(bytes) + local packet = ProtocolManager.read(buffer) + return packet +end + -------------------------------------UTF8------------------------------------- -- 判断utf8字符byte长度 -- 0xxxxxxx - 1 byte @@ -396,9 +406,8 @@ end --char function ByteBuffer:writeChar(charValue) - if str == nil or #str == 0 then - self:writeInt(0) - self:writeByte(0) + if charValue == nil or #charValue == 0 then + self:writeString("") return end local str = utf8sub(charValue, 1, 1) @@ -450,4 +459,253 @@ function ByteBuffer:getBytes(startIndex, endIndex) return table.concat(self.buffer, "", startIndex, endIndex) end +function ByteBuffer:writePacketFlag(value) + local flag = (value == null) + self:writeBoolean(not flag) + return flag +end + +function ByteBuffer:writePacket(value, protocolId) + local protocolRegistration = ProtocolManager.getProtocol(protocolId) + protocolRegistration:write(self, value) + return self +end + +function ByteBuffer:readPacket(protocolId) + local protocolRegistration = ProtocolManager.getProtocol(protocolId) + return protocolRegistration:read(self) +end + +function ByteBuffer:writeBooleanArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeBoolean(element) + end + end + return self +end + +function ByteBuffer:readBooleanArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readBoolean()) + end + end + return array +end + +function ByteBuffer:writeByteArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeByte(element) + end + end + return self +end + +function ByteBuffer:readByteArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readByte()) + end + end + return array +end + +function ByteBuffer:writeShortArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeShort(element) + end + end + return self +end + +function ByteBuffer:readShortArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readShort()) + end + end + return array +end + +function ByteBuffer:writeIntArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeInt(element) + end + end + return self +end + +function ByteBuffer:readIntArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readInt()) + end + end + return array +end + +function ByteBuffer:writeLongArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeLong(element) + end + end + return self +end + +function ByteBuffer:readLongArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readLong()) + end + end + return array +end + +function ByteBuffer:writeFloatArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeFloat(element) + end + end + return self +end + +function ByteBuffer:readFloatArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readFloat()) + end + end + return array +end + +function ByteBuffer:writeDoubleArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeDouble(element) + end + end + return self +end + +function ByteBuffer:readDoubleArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readDouble()) + end + end + return array +end + +function ByteBuffer:writeCharArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeChar(element) + end + end + return self +end + +function ByteBuffer:readCharArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readChar()) + end + end + return array +end + +function ByteBuffer:writeStringArray(array) + if array == null then + self:writeInt(0) + else + self:writeInt(#array); + for index, element in pairs(array) do + self:writeString(element) + end + end + return self +end + +function ByteBuffer:readStringArray() + local array = {} + local size = self:readInt() + if size > 0 then + for index = 1, size do + table.insert(array, self:readString()) + end + end + return array +end + +function ByteBuffer:writePacketArray(array, protocolId) + if array == null then + self:writeInt(0) + else + local protocolRegistration = ProtocolManager.getProtocol(protocolId) + self:writeInt(#array); + for index, element in pairs(array) do + protocolRegistration:write(self, element) + end + end + return self +end + +function ByteBuffer:readPacketArray(protocolId) + local array = {} + local size = self:readInt() + if size > 0 then + local protocolRegistration = ProtocolManager.getProtocol(protocolId) + for index = 1, size do + table.insert(array, protocolRegistration:read(self)) + end + end + return array +end + return ByteBuffer \ No newline at end of file diff --git a/protocol/src/main/resources/lua/ProtocolManager.lua b/protocol/src/main/resources/lua/ProtocolManager.lua index d475d16e..63ad1bbc 100644 --- a/protocol/src/main/resources/lua/ProtocolManager.lua +++ b/protocol/src/main/resources/lua/ProtocolManager.lua @@ -30,24 +30,24 @@ function ProtocolManager.getProtocol(protocolId) return protocol end -function ProtocolManager.write(byteBuffer, packet) +function ProtocolManager.write(buffer, packet) local protocolId = packet:protocolId() -- 写入协议号 - byteBuffer:writeShort(protocolId) + buffer:writeShort(protocolId) -- 写入包体 - ProtocolManager.getProtocol(protocolId):write(byteBuffer, packet) + ProtocolManager.getProtocol(protocolId):write(buffer, packet) end -function ProtocolManager.read(byteBuffer) - local protocolId = byteBuffer:readShort() - return ProtocolManager.getProtocol(protocolId):read(byteBuffer) +function ProtocolManager.read(buffer) + local protocolId = buffer:readShort() + return ProtocolManager.getProtocol(protocolId):read(buffer) end -- C#传进来的byte数组到lua里就会变成string function readBytes(bytes) - local byteBuffer = ByteBuffer:new() - byteBuffer:writeBuffer(bytes) - local packet = ProtocolManager.read(byteBuffer) + local buffer = ByteBuffer:new() + buffer:writeBuffer(bytes) + local packet = ProtocolManager.read(buffer) return packet end