Start TEngine3.0

Start TEngine3.0
This commit is contained in:
ALEXTANG
2023-03-31 17:27:49 +08:00
parent 179765c43c
commit 36353294d6
1032 changed files with 21868 additions and 102407 deletions

View File

@@ -0,0 +1,108 @@
{{
is_value_type = x.is_value_type
is_abstract_type = x.is_abstract_type
name = x.name
full_name = x.full_name
parent_def_type = x.parent_def_type
parent = x.parent
fields = x.fields
hierarchy_fields = x.hierarchy_fields
}}
using Bright.Serialization;
namespace {{x.namespace_with_top_module}}
{
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public {{if is_value_type}}struct{{else}}{{x.cs_class_modifier}} class{{end}} {{name}} : {{if parent_def_type}} {{parent}} {{else}} Bright.Serialization.BeanBase {{end}}
{
{{~if !is_value_type~}}
public {{name}}()
{
}
{{~end~}}
public {{name}}(Bright.Common.NotNullInitialization _) {{if parent_def_type}} : base(_) {{end}}
{
{{~ for field in fields ~}}
{{~if cs_need_init field.ctype~}}
{{cs_init_field_ctor_value field.convention_name field.ctype}}
{{~else if is_value_type~}}
{{field.convention_name}} = default;
{{~end~}}
{{~end~}}
}
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
{
{{~if is_abstract_type~}}
_buf.WriteInt(x.GetTypeId());
x.Serialize(_buf);
{{~else~}}
x.Serialize(_buf);
{{~end~}}
}
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
{
{{~if is_abstract_type~}}
{{full_name}} x;
switch (_buf.ReadInt())
{
{{~ for child in x.hierarchy_not_abstract_children~}}
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break;
{{~end~}}
default: throw new SerializationException();
}
x.Deserialize(_buf);
{{~else~}}
var x = new {{full_name}}();
x.Deserialize(_buf);
{{~end~}}
return x;
}
{{~ for field in fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}};
{{~end~}}
{{~if !is_abstract_type~}}
public const int __ID__ = {{x.id}};
public override int GetTypeId() => __ID__;
public override void Serialize(ByteBuf _buf)
{
{{~ for field in hierarchy_fields ~}}
{{cs_serialize '_buf' field.convention_name field.ctype}}
{{~end~}}
}
public override void Deserialize(ByteBuf _buf)
{
{{~ for field in hierarchy_fields ~}}
{{cs_deserialize '_buf' field.convention_name field.ctype}}
{{~end~}}
}
public override string ToString()
{
return "{{full_name}}{ "
{{~ for field in hierarchy_fields ~}}
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
{{~end~}}
+ "}";
}
{{~end~}}
}
}

View File

@@ -0,0 +1,81 @@
{{
name = x.name
full_name = x.full_name
parent = x.parent
fields = x.fields
}}
using Bright.Serialization;
namespace {{x.namespace_with_top_module}}
{
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public sealed class {{name}} : Bright.Net.Codecs.Protocol
{
{{~ for field in fields ~}}
{{~if field.comment != '' ~}}
/// <summary>
/// {{field.escape_comment}}
/// </summary>
{{~end~}}
public {{cs_define_type field.ctype}} {{field.convention_name}};
{{~end~}}
public {{name}}()
{
}
public {{name}}(Bright.Common.NotNullInitialization _)
{
{{~ for field in fields ~}}
{{~if cs_need_init field.ctype~}}
{{cs_init_field_ctor_value field.convention_name field.ctype}}
{{~end~}}
{{~end~}}
}
public const int __ID__ = {{x.id}};
public override int GetTypeId()
{
return __ID__;
}
public override void Serialize(ByteBuf _buf)
{
{{~ for field in fields ~}}
{{cs_serialize '_buf' field.convention_name field.ctype}}
{{~end~}}
}
public override void Deserialize(ByteBuf _buf)
{
{{~ for field in fields ~}}
{{cs_deserialize '_buf' field.convention_name field.ctype}}
{{~end~}}
}
public override void Reset()
{
throw new System.NotImplementedException();
}
public override object Clone()
{
throw new System.NotImplementedException();
}
public override string ToString()
{
return "{{full_name}}{ "
{{~ for field in fields ~}}
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
{{~end~}}
+ "}";
}
}
}

View File

@@ -0,0 +1,47 @@
{{
name = x.name
full_name = x.full_name
parent = x.parent
fields = x.fields
targ_type = x.targ_type
tres_type = x.tres_type
}}
using Bright.Serialization;
namespace {{x.namespace_with_top_module}}
{
{{~if x.comment != '' ~}}
/// <summary>
/// {{x.escape_comment}}
/// </summary>
{{~end~}}
public sealed class {{name}} : Bright.Net.Codecs.Rpc<{{cs_define_type targ_type}}, {{cs_define_type tres_type}}>
{
public {{name}}()
{
}
public const int __ID__ = {{x.id}};
public override int GetTypeId()
{
return __ID__;
}
public override void Reset()
{
throw new System.NotImplementedException();
}
public override object Clone()
{
throw new System.NotImplementedException();
}
public override string ToString()
{
return $"{{full_name}}{%{ {{arg:{Arg},res:{Res} }} }%}";
}
}
}

View File

@@ -0,0 +1,19 @@
using Bright.Serialization;
namespace {{namespace}}
{
public static class {{name}}
{
public static System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator> Factories { get; } = new System.Collections.Generic.Dictionary<int, Bright.Net.Codecs.ProtocolCreator>
{
{{~ for proto in protos ~}}
[{{proto.full_name}}.__ID__] = () => new {{proto.full_name}}(),
{{~end~}}
{{~ for rpc in rpcs ~}}
[{{rpc.full_name}}.__ID__] = () => new {{rpc.full_name}}(),
{{~end~}}
};
}
}