From 034f0dd21b4097e61ed08bcc6b5711e61f8d0dbf Mon Sep 17 00:00:00 2001 From: walon Date: Sun, 13 Feb 2022 11:57:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dproto=20c#=E5=AF=B9=E5=8F=AF=E7=A9=BA=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=BA=8F=E5=88=97=E5=8C=96=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/TypeVisitors/CsSerializeVisitor.cs | 7 +------ src/Luban.Server/Templates/proto/cs/bean.tpl | 12 ++---------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs b/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs index dae970f..0fcada8 100644 --- a/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs +++ b/src/Luban.Job.Common/Source/TypeVisitors/CsSerializeVisitor.cs @@ -10,17 +10,12 @@ namespace Luban.Job.Common.TypeVisitors { if (type.IsNullable) { - return $"if({fieldName} != null){{ {bufName}.WriteBool(true); {type.Apply(CsUnderingSerializeVisitor.Ins, bufName, type.Apply(CsIsRawNullableTypeVisitor.Ins) ? fieldName : fieldName + ".Value" )} }} else {{ {bufName}.WriteBool(true); }}"; + return $"{{ if({fieldName} is {type.Apply(CsUnderingDefineTypeName.Ins)} __value__){{ {bufName}.WriteBool(true); {type.Apply(CsUnderingSerializeVisitor.Ins, bufName, "__value__" )} }} else {{ {bufName}.WriteBool(false); }} }}"; } else { return type.Apply(CsUnderingSerializeVisitor.Ins, bufName, fieldName); } } - - public override string Accept(TBean type, string bufName, string fieldName) - { - return type.Apply(CsUnderingSerializeVisitor.Ins, bufName, fieldName); - } } } diff --git a/src/Luban.Server/Templates/proto/cs/bean.tpl b/src/Luban.Server/Templates/proto/cs/bean.tpl index 1e3006a..20275fc 100644 --- a/src/Luban.Server/Templates/proto/cs/bean.tpl +++ b/src/Luban.Server/Templates/proto/cs/bean.tpl @@ -40,15 +40,8 @@ namespace {{x.namespace_with_top_module}} public static void Serialize{{name}}(ByteBuf _buf, {{name}} x) { {{~if is_abstract_type~}} - if (x != null) - { - _buf.WriteInt(x.GetTypeId()); - x.Serialize(_buf); - } - else - { - _buf.WriteInt(0); - } + _buf.WriteInt(x.GetTypeId()); + x.Serialize(_buf); {{~else~}} x.Serialize(_buf); {{~end~}} @@ -60,7 +53,6 @@ namespace {{x.namespace_with_top_module}} {{full_name}} x; switch (_buf.ReadInt()) { - case 0 : return null; {{~ for child in x.hierarchy_not_abstract_children~}} case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break; {{~end~}}