【特性】proto 生成的typescript代码包含constructor函数,默认构造了初始值
parent
5c038ca449
commit
bf3cae5d1a
|
|
@ -128,6 +128,7 @@ namespace Luban.Job.Common.Defs
|
|||
case "int": return nullable ? TInt.NullableIns : TInt.Ins;
|
||||
case "fint": return nullable ? TFint.NullableIns : TFint.Ins;
|
||||
case "long": return nullable ? TLong.NullableIns : TLong.Ins;
|
||||
case "bigint": return nullable ? TLong.NullableBigIns : TLong.BigIns;
|
||||
case "flong": return nullable ? TFlong.NullableIns : TFlong.Ins;
|
||||
case "float": return nullable ? TFloat.NullableIns : TFloat.Ins;
|
||||
case "double": return nullable ? TDouble.NullableIns : TDouble.Ins;
|
||||
|
|
|
|||
|
|
@ -133,6 +133,11 @@ namespace Luban.Job.Common.Defs
|
|||
return $"{filedName}";
|
||||
}
|
||||
|
||||
public static string TsCtorDefaultValue(TType type)
|
||||
{
|
||||
return type.Apply(TypescriptCtorValueVisitor.Ins);
|
||||
}
|
||||
|
||||
public static string TsConstValue(TType type, string value)
|
||||
{
|
||||
return type.Apply(LuaConstValueVisitor.Ins, value);
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
using Luban.Job.Common.Types;
|
||||
|
||||
namespace Luban.Job.Common.TypeVisitors
|
||||
{
|
||||
//public class NeedMarshalBoolPrefixVisitor : DecoratorFuncVisitor<bool>
|
||||
//{
|
||||
// //public static NeedMarshalBoolPrefixVisitor Ins { get; } = new NeedMarshalBoolPrefixVisitor();
|
||||
|
||||
// public override bool DoAccept(TType type)
|
||||
// {
|
||||
// return type.IsNullable && !(type is TBean bean && bean.IsDynamic);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
|
@ -18,10 +18,5 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
return type.Apply(TypescriptBinUnderingDeserializeVisitor.Ins, byteBufName, fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Accept(TBean type, string bufName, string fieldName)
|
||||
{
|
||||
return type.Apply(TypescriptBinUnderingDeserializeVisitor.Ins, bufName, fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,5 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
return type.Apply(TypescriptBinUnderingSerializeVisitor.Ins, bytebufName, fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Accept(TBean type, string bufName, string fieldName)
|
||||
{
|
||||
return type.Apply(TypescriptBinUnderingSerializeVisitor.Ins, bufName, fieldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
|
||||
public string Accept(TLong type, string bufName, string fieldName)
|
||||
{
|
||||
return $"{fieldName} = {bufName}.ReadLong();";
|
||||
return $"{fieldName} = {bufName}.{(type.IsBigInt ? "ReadLong" : "ReadLongAsNumber")}();";
|
||||
}
|
||||
|
||||
public string Accept(TFlong type, string bufName, string fieldName)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
|
||||
public string Accept(TLong type, string bufName, string fieldName)
|
||||
{
|
||||
return $"{bufName}.WriteLong({fieldName});";
|
||||
return $"{bufName}.{(type.IsBigInt ? "WriteLong" : "WriteNumberAsLong")}({fieldName});";
|
||||
}
|
||||
|
||||
public string Accept(TFlong type, string bufName, string fieldName)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
using Luban.Job.Common.Types;
|
||||
using System;
|
||||
|
||||
namespace Luban.Job.Common.TypeVisitors
|
||||
{
|
||||
public class TypescriptCtorValueVisitor : ITypeFuncVisitor<string>
|
||||
{
|
||||
public static TypescriptCtorValueVisitor Ins { get; } = new();
|
||||
|
||||
public string Accept(TBool type)
|
||||
{
|
||||
return "false";
|
||||
}
|
||||
|
||||
public string Accept(TByte type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TShort type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TFshort type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TInt type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TFint type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TLong type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TFlong type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TFloat type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TDouble type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TEnum type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public string Accept(TString type)
|
||||
{
|
||||
return "\"\"";
|
||||
}
|
||||
|
||||
public string Accept(TBytes type)
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
|
||||
public string Accept(TText type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string Accept(TBean type)
|
||||
{
|
||||
return type.IsDynamic ? "null" : $"new {type.Bean.FullName}()";
|
||||
}
|
||||
|
||||
public string Accept(TArray type)
|
||||
{
|
||||
return "[]";
|
||||
}
|
||||
|
||||
public string Accept(TList type)
|
||||
{
|
||||
return "[]";
|
||||
}
|
||||
|
||||
public string Accept(TSet type)
|
||||
{
|
||||
return "new Set()";
|
||||
}
|
||||
|
||||
public string Accept(TMap type)
|
||||
{
|
||||
return "new Map()";
|
||||
}
|
||||
|
||||
public string Accept(TVector2 type)
|
||||
{
|
||||
return "new Vector2(0,0)";
|
||||
}
|
||||
|
||||
public string Accept(TVector3 type)
|
||||
{
|
||||
return "new Vector3(0,0,0)";
|
||||
}
|
||||
|
||||
public string Accept(TVector4 type)
|
||||
{
|
||||
return "new Vector4(0,0,0,0)";
|
||||
}
|
||||
|
||||
public string Accept(TDateTime type)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ namespace Luban.Job.Common.TypeVisitors
|
|||
|
||||
public string Accept(TLong type)
|
||||
{
|
||||
return "bigint";
|
||||
return type.IsBigInt ? "bigint" : "number";
|
||||
}
|
||||
|
||||
public string Accept(TFlong type)
|
||||
|
|
|
|||
|
|
@ -4,12 +4,19 @@ namespace Luban.Job.Common.Types
|
|||
{
|
||||
public class TLong : TType
|
||||
{
|
||||
public static TLong Ins { get; } = new TLong(false);
|
||||
public static TLong Ins { get; } = new TLong(false, false);
|
||||
|
||||
public static TLong NullableIns { get; } = new TLong(true);
|
||||
public static TLong NullableIns { get; } = new TLong(true, false);
|
||||
|
||||
public TLong(bool isNullable) : base(isNullable)
|
||||
public static TLong BigIns { get; } = new TLong(false, true);
|
||||
|
||||
public static TLong NullableBigIns { get; } = new TLong(true, true);
|
||||
|
||||
public bool IsBigInt { get; }
|
||||
|
||||
public TLong(bool isNullable, bool isBigInt) : base(isNullable)
|
||||
{
|
||||
IsBigInt = isBigInt;
|
||||
}
|
||||
|
||||
public override bool TryParseFrom(string s)
|
||||
|
|
|
|||
|
|
@ -89,6 +89,14 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} extends {{if pa
|
|||
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields ~}}
|
||||
this.{{field.ts_style_name}} = {{ts_ctor_default_value field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
|
||||
serialize(_buf_ : Bright.Serialization.ByteBuf) {
|
||||
{{~if parent_def_type~}}
|
||||
super.serialize(_buf_)
|
||||
|
|
@ -144,6 +152,13 @@ export class {{name}} extends Protocol {
|
|||
{{field.ts_style_name}}{{if field.is_nullable}}?{{end}} : {{ts_define_type field.ctype}}
|
||||
{{~end~}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields ~}}
|
||||
this.{{field.ts_style_name}} = {{ts_ctor_default_value field.ctype}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
serialize(_buf_ : Bright.Serialization.ByteBuf) {
|
||||
{{~ for field in fields ~}}
|
||||
{{ts_bin_serialize ('this.' + field.ts_style_name) '_buf_' field.ctype}}
|
||||
|
|
|
|||
Loading…
Reference in New Issue