mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-04 08:20:03 +00:00
feat[lua]: compatible field of inside protocol class in lua
This commit is contained in:
@@ -100,10 +100,10 @@ public abstract class GenerateLuaUtils {
|
||||
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);
|
||||
@@ -167,7 +167,7 @@ public abstract class GenerateLuaUtils {
|
||||
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);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
--右移操作>>是无符号右移
|
||||
--local Long = require("Long")
|
||||
|
||||
local ProtocolManager = require("ProtocolManager")
|
||||
local ProtocolManager = require("zfoolua.ProtocolManager")
|
||||
|
||||
local maxInt = 2147483647
|
||||
local minInt = -2147483648
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user