[new] 新增bidx,即binary格式的索引文件输出。方便优化按需加载

main
walon 2022-07-19 11:42:49 +08:00
parent abcacebcaa
commit 665b9a4cea
5 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,40 @@
using Bright.Serialization;
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.DataSources;
using Luban.Job.Cfg.DataVisitors;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.RawDefs;
using System;
using System.Collections.Generic;
namespace Luban.Job.Cfg.DataExporters
{
class BinaryIndexExportor
{
public static BinaryIndexExportor Ins { get; } = new BinaryIndexExportor();
public void WriteList(DefTable table, List<Record> datas, ByteBuf x)
{
x.WriteSize(datas.Count);
var tableDataBuf = new ByteBuf(10 * 1024);
tableDataBuf.WriteSize(datas.Count);
foreach (var d in datas)
{
int offset = tableDataBuf.Size;
d.Data.Apply(BinaryExportor.Ins, tableDataBuf);
string keyStr = "";
foreach (IndexInfo index in table.IndexList)
{
DType key = d.Data.Fields[index.IndexFieldIdIndex];
key.Apply(BinaryExportor.Ins, x);
keyStr += key.ToString() + ",";
}
x.WriteSize(offset);
Console.WriteLine($"table:{table.Name} key:{keyStr} offset:{offset}");
}
}
}
}

View File

@ -8,7 +8,7 @@ namespace Luban.Job.Cfg
[Option('s', "service", Required = true, HelpText = "service")]
public string Service { get; set; }
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_dotnet_json,code_cs_unity_json,code_cs_unity_editor_json,code_lua_bin,code_java_bin,code_java_json,code_go_bin,code_go_json,code_cpp_bin,code_cpp_ue_editor_json,code_python2_json,code_python3_json,code_typescript_bin,code_typescript_json,code_rust_json,code_protobuf,code_template,code_flatbuffers,code_gdscript_json,data_bin,data_lua,data_json,data_json2,data_json_monolithic,data_yaml,data_xml,data_resources,data_template,data_protobuf_bin,data_protobuf_json,data_flatbuffers_json,convert_json,convert_lua,convert_xlsx . can be multi")]
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_dotnet_json,code_cs_unity_json,code_cs_unity_editor_json,code_lua_bin,code_java_bin,code_java_json,code_go_bin,code_go_json,code_cpp_bin,code_cpp_ue_editor_json,code_python2_json,code_python3_json,code_typescript_bin,code_typescript_json,code_rust_json,code_protobuf,code_template,code_flatbuffers,code_gdscript_json,data_bin,data_bidx,data_lua,data_json,data_json2,data_json_monolithic,data_bson,data_yaml,data_xml,data_resources,data_template,data_protobuf_bin,data_protobuf_json,data_flatbuffers_json,convert_json,convert_lua,convert_xlsx . can be multi")]
public string GenType { get; set; }
[Option("input_data_dir", Required = true, HelpText = "input data dir")]

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
namespace Luban.Job.Cfg.Generate
{
[Render("data_bin")]
[Render("data_bidx")]
[Render("data_json")]
[Render("data_json2")]
[Render("data_bson")]

View File

@ -44,6 +44,14 @@ namespace Luban.Job.Cfg.Utils
ThreadLocalTemporalByteBufPool.Free(buf);
return bytes;
}
case "data_bidx":
{
var buf = ThreadLocalTemporalByteBufPool.Alloc(1024 * 1024);
BinaryIndexExportor.Ins.WriteList(table, records, buf);
var bytes = buf.CopyData();
ThreadLocalTemporalByteBufPool.Free(buf);
return bytes;
}
case "data_json":
case "data_json2":
{

View File

@ -111,9 +111,10 @@ namespace Luban.Job.Common.Utils
private static readonly Dictionary<string, string> s_name2Suxxifx = new()
{
{ "json", "json" },
{"bson", "bson" },
{ "bson", "bson" },
{ "lua", "lua" },
{ "bin", "bytes" },
{ "bidx", "bytes" },
{ "xml", "xml" },
{ "yaml", "yml" },
{ "yml", "yml" },