Skip to content

Commit

Permalink
feat[lua]: compatible field of inside protocol class in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Oct 18, 2023
1 parent e40f9ec commit 9d393e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public static void createProtocolManager(List<IProtocolRegistration> protocolLis
var protocolName = protocol.protocolConstructor().getDeclaringClass().getSimpleName();
var path = GenerateProtocolPath.getProtocolPath(protocolId);
if (StringUtils.isBlank(path)) {
fieldBuilder.append(TAB).append(StringUtils.format("local {} = require(\"{}\")", protocolName, protocolName)).append(LS);
fieldBuilder.append(TAB).append(StringUtils.format("local {} = require(\"{}.{}\")", protocolName, protocolOutputRootPath, protocolName)).append(LS);
} else {
fieldBuilder.append(TAB).append(StringUtils.format("local {} = require(\"{}.{}\")"
, protocolName, path.replaceAll(StringUtils.SLASH, StringUtils.PERIOD), protocolName)).append(LS);
fieldBuilder.append(TAB).append(StringUtils.format("local {} = require(\"{}.{}.{}\")"
, protocolName,protocolOutputRootPath, path.replaceAll(StringUtils.SLASH, StringUtils.PERIOD), protocolName)).append(LS);
}

protocolBuilder.append(TAB).append(StringUtils.format("protocols[{}] = {}", protocolId, protocolName)).append(LS);
Expand Down Expand Up @@ -167,7 +167,7 @@ private static String writePacket(ProtocolRegistration registration) {
var fieldRegistrations = registration.getFieldRegistrations();
var luaBuilder = new StringBuilder();
if (registration.isCompatible()) {
luaBuilder.append("local beforeWriteIndex = buffer:getWriteOffset(;").append(LS);
luaBuilder.append("local beforeWriteIndex = buffer:getWriteOffset()").append(LS);
luaBuilder.append(TAB).append(StringUtils.format("buffer:writeInt({})", registration.getPredictionLength())).append(LS);
} else {
luaBuilder.append(TAB).append("buffer:writeInt(-1)").append(LS);
Expand Down
10 changes: 5 additions & 5 deletions protocol/src/main/resources/lua/ByteBuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
--右移操作>>是无符号右移
--local Long = require("Long")

local ProtocolManager = require("ProtocolManager")
local ProtocolManager = require("zfoolua.ProtocolManager")

local maxInt = 2147483647
local minInt = -2147483648
Expand Down Expand Up @@ -99,9 +99,9 @@ function ByteBuffer:adjustPadding(predictionLength, beforeWriteIndex)
self:setWriteOffset(currentWriteIndex)
else
local bytes = self:getBytes(currentWriteIndex - length, currentWriteIndex - 1)
self:setWriteOffset(currentWriteIndex - length)
self:setWriteOffset(beforeWriteIndex)
self:writeInt(length)
self:writeRawByteStr(bytes)
self:writeBuffer(bytes)
end
end

Expand Down Expand Up @@ -232,8 +232,8 @@ function ByteBuffer:writeIntCount(intValue)
end

--lua中的右移为无符号右移,要特殊处理
local mask = longValue >> 63
local value = longValue << 1
local mask = intValue >> 63
local value = intValue << 1
if (mask == 1) then
value = value ~ 0xFFFFFFFFFFFFFFFF
end
Expand Down

0 comments on commit 9d393e7

Please sign in to comment.