parent
ab559c17ea
commit
f3aa518526
|
|
@ -0,0 +1,60 @@
|
||||||
|
using Luban.Job.Common.Types;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Common.TypeVisitors
|
||||||
|
{
|
||||||
|
public class CsCtorValueVisitor : DecoratorFuncVisitor<string>
|
||||||
|
{
|
||||||
|
public static CsCtorValueVisitor Ins { get; } = new CsCtorValueVisitor();
|
||||||
|
|
||||||
|
public override string DoAccept(TType type)
|
||||||
|
{
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override string Accept(TString type)
|
||||||
|
{
|
||||||
|
return "\"\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Accept(TBytes type)
|
||||||
|
{
|
||||||
|
return "System.Array.Empty<byte>()";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Accept(TText type)
|
||||||
|
{
|
||||||
|
return "\"\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Accept(TBean type)
|
||||||
|
{
|
||||||
|
return type.Bean.IsAbstractType ? "default" : $"new {type.Apply(CsDefineTypeName.Ins)}()";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Accept(TArray type)
|
||||||
|
{
|
||||||
|
return $"System.Array.Empty<{type.ElementType.Apply(CsDefineTypeName.Ins)}>()";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Accept(TList type)
|
||||||
|
{
|
||||||
|
return $"new System.Collections.Generic.List<{type.ElementType.Apply(CsDefineTypeName.Ins)}>()";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Accept(TSet type)
|
||||||
|
{
|
||||||
|
return $"new System.Collections.Generic.HashSet<{type.ElementType.Apply(CsDefineTypeName.Ins)}>()";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Accept(TMap type)
|
||||||
|
{
|
||||||
|
return $"new System.Collections.Generic.Dictionary<{type.KeyType.Apply(CsDefineTypeName.Ins)},{type.ValueType.Apply(CsDefineTypeName.Ins)}>()";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -68,9 +68,10 @@ namespace Luban.Job.Db.Defs
|
||||||
return $"{field.CsStyleName} = default;";
|
return $"{field.CsStyleName} = default;";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CsWriteBlob(string bufName, string valueName, TType type)
|
public static string CsWriteBlob(string bufName, string fieldName, TType type)
|
||||||
{
|
{
|
||||||
return type.Apply(DbWriteBlob.Ins, bufName, valueName);
|
//return type.Apply(DbWriteBlob.Ins, bufName, valueName);
|
||||||
|
return DbCsCompatibleSerialize(bufName, fieldName, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,133 +4,9 @@ using System;
|
||||||
|
|
||||||
namespace Luban.Job.Db.TypeVisitors
|
namespace Luban.Job.Db.TypeVisitors
|
||||||
{
|
{
|
||||||
class DbWriteBlob : ITypeFuncVisitor<string, string, string>
|
class DbWriteBlob
|
||||||
{
|
{
|
||||||
public static DbWriteBlob Ins { get; } = new DbWriteBlob();
|
public static DbCsCompatibleSerializeVisitor Ins { get; } = new DbCsCompatibleSerializeVisitor();
|
||||||
|
|
||||||
public string Accept(TBool type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteBool({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TByte type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteByte({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TShort type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteShort({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TFshort type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteFshort({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TInt type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteInt({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TFint type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteFint({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TLong type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteLong({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TFlong type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteFlong({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TFloat type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteFloat({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TDouble type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteDouble({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TEnum type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteInt((int){fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TString type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteString({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TBytes type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteBytes({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TText type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteString({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TBean type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
var bean = type.Bean;
|
|
||||||
if (bean.IsNotAbstractType)
|
|
||||||
{
|
|
||||||
|
|
||||||
return $"{fieldName}.Serialize({byteBufName});";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return $"{bean.FullName}.Serialize{bean.Name}({byteBufName}, {fieldName});";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TArray type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteSize({fieldName}.Length); foreach(var _e in {fieldName}) {{ {type.ElementType.Apply(this, byteBufName, "_e")} }}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TList type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteSize({fieldName}.Count); foreach(var _e in {fieldName}) {{ {type.ElementType.Apply(this, byteBufName, "_e")} }}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TSet type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteSize({fieldName}.Count); foreach(var _e in {fieldName}) {{ {type.ElementType.Apply(this, byteBufName, "_e")} }}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TMap type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteSize({fieldName}.Count); foreach((var _k, var _v) in {fieldName}) {{ {type.KeyType.Apply(this, byteBufName, "_k")} {type.ValueType.Apply(this, byteBufName, "_v")}}}";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TVector2 type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteVector2({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TVector3 type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteVector3({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TVector4 type, string byteBufName, string fieldName)
|
|
||||||
{
|
|
||||||
return $"{byteBufName}.WriteVector4({fieldName});";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Accept(TDateTime type, string x, string y)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ namespace Luban.Job.Proto.Defs
|
||||||
return type.Apply(LuaUnderingDeserializeVisitor.Ins, bufName);
|
return type.Apply(LuaUnderingDeserializeVisitor.Ins, bufName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CsInitFieldCtorValue(DefField field)
|
public static string CsInitFieldCtorValue(string bufName, TType type)
|
||||||
{
|
{
|
||||||
return $"{field.CsStyleName} = default;";
|
return $"{bufName} = {type.Apply(CsCtorValueVisitor.Ins)};";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,9 @@ namespace {{x.namespace_with_top_module}}
|
||||||
{
|
{
|
||||||
{{~ for field in fields ~}}
|
{{~ for field in fields ~}}
|
||||||
{{~if cs_need_init field.ctype~}}
|
{{~if cs_need_init field.ctype~}}
|
||||||
{{cs_init_field_ctor_value field}}
|
{{cs_init_field_ctor_value field.cs_style_name field.ctype}}
|
||||||
{{~else if is_value_type~}}
|
{{~else if is_value_type~}}
|
||||||
{field.cs_style_name} = default;
|
{{field.cs_style_name}} = default;
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
|
|
@ -178,8 +178,8 @@ namespace {{x.namespace_with_top_module}}
|
||||||
public {{name}}(Bright.Common.NotNullInitialization _)
|
public {{name}}(Bright.Common.NotNullInitialization _)
|
||||||
{
|
{
|
||||||
{{~ for field in fields ~}}
|
{{~ for field in fields ~}}
|
||||||
{{~if field.ctype.need_init~}}
|
{{~if cs_need_init field.ctype~}}
|
||||||
{{cs_init_field_ctor_value field}}
|
{{cs_init_field_ctor_value field.cs_style_name field.ctype}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
{{~end~}}
|
{{~end~}}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue