mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-24 02:26:23 +00:00
perf[lua]: convert the array or map of Lua to a normal output string
This commit is contained in:
@@ -276,14 +276,7 @@ public abstract class GenerateLuaUtils {
|
||||
var params = new ArrayList<String>();
|
||||
for (var field : sequencedFields) {
|
||||
var fieldName = field.getName();
|
||||
var fieldRegistration = fieldRegistrations[GenerateProtocolFile.indexOf(fields, field)];
|
||||
if ((fieldRegistration instanceof ArrayField) || (fieldRegistration instanceof ListField)) {
|
||||
params.add(StringUtils.format("{}:[%s]", fieldName));
|
||||
} else if (fieldRegistration instanceof MapField) {
|
||||
params.add(StringUtils.format("{}:{%s}", fieldName));
|
||||
} else {
|
||||
params.add(StringUtils.format("{}:%s", fieldName));
|
||||
}
|
||||
params.add(StringUtils.format("{}:%s", fieldName));
|
||||
}
|
||||
luaBuilder.append(StringUtils.joinWith(", ", params.toArray()));
|
||||
luaBuilder.append("}");
|
||||
@@ -303,8 +296,10 @@ public abstract class GenerateLuaUtils {
|
||||
for (var field : sequencedFields) {
|
||||
var fieldName = field.getName();
|
||||
var fieldRegistration = fieldRegistrations[GenerateProtocolFile.indexOf(fields, field)];
|
||||
if ((fieldRegistration instanceof ArrayField) || (fieldRegistration instanceof ListField) || (fieldRegistration instanceof MapField)) {
|
||||
params.add(StringUtils.format("table.concat(self.{}, \", \")", fieldName));
|
||||
if ((fieldRegistration instanceof ArrayField) || (fieldRegistration instanceof ListField)) {
|
||||
params.add(StringUtils.format("table.arrayToString(self.{})", fieldName));
|
||||
} else if (fieldRegistration instanceof MapField) {
|
||||
params.add(StringUtils.format("table.mapToString(self.{})", fieldName));
|
||||
} else {
|
||||
params.add(StringUtils.format("self.{}", fieldName));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,24 @@ local ByteBuffer = {}
|
||||
local trueBooleanStrValue = string.char(1)
|
||||
local falseBooleanStrValue = string.char(0)
|
||||
|
||||
function table.arrayToString(array)
|
||||
local items = {}
|
||||
for index, element in pairs(array) do
|
||||
table.insert(items, tostring(element))
|
||||
end
|
||||
local result = table.concat(items, ", ")
|
||||
return "[" .. result .. "]";
|
||||
end
|
||||
|
||||
function table.mapToString(map)
|
||||
local items = {}
|
||||
for key, value in pairs(map) do
|
||||
table.insert(items, key .. ":" .. value)
|
||||
end
|
||||
local result = table.concat(items, ", ")
|
||||
return "{" .. result .. "}";
|
||||
end
|
||||
|
||||
-------------------------------------构造器-------------------------------------
|
||||
function ByteBuffer:new()
|
||||
--buffer里的每一个元素为一个长度为1的字符串
|
||||
|
||||
Reference in New Issue
Block a user