From 56c222976ee71349be780303b25eb245c17e5ea9 Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 30 Nov 2021 10:32:47 +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=8Dcfg=20data=5Fprotobuf=E5=AF=BC=E5=87=BA=E5=A4=9A?= =?UTF-8?q?=E6=80=81=E7=BB=93=E6=9E=84=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82=E5=B7=B2=E7=BB=8F=E9=80=9A=E8=BF=87=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=B5=8B=E8=AF=95=E3=80=82=E5=AE=8C=E7=BE=8E=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataExporters/ProtobufExportor.cs | 46 +++++++++++++++---- src/Luban.Server/Templates/config/pb2/all.tpl | 3 ++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs b/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs index 6e8ee9c..1b884fa 100644 --- a/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs +++ b/src/Luban.Job.Cfg/Source/DataExporters/ProtobufExportor.cs @@ -166,16 +166,14 @@ namespace Luban.Job.Cfg.DataExporters FreeMemoryStream(ms); } - public void Accept(DBean type, CodedOutputStream x) + private void WriteRawMessageWithoutLength(DBean type, CodedOutputStream temp) { - var bean = type.Type; - if (bean.IsAbstractType) - { - x.WriteTag(type.ImplType.AutoId, WireFormat.WireType.LengthDelimited); - } - - var ms = AllocMemoryStream(); - var temp = new CodedOutputStream(ms); + //var ms = AllocMemoryStream(); + //var temp = new CodedOutputStream(ms); + //if (bean.IsAbstractType) + //{ + // temp.WriteTag(type.ImplType.AutoId, WireFormat.WireType.LengthDelimited); + //} var defFields = type.ImplType.HierarchyFields; int index = 0; @@ -221,6 +219,18 @@ namespace Luban.Job.Cfg.DataExporters } } } + //temp.Flush(); + //ms.Seek(0, SeekOrigin.Begin); + //var bs = ByteString.FromStream(ms); + //x.WriteBytes(bs); + //FreeMemoryStream(ms); + } + + private void EnterScope(CodedOutputStream x, Action action) + { + var ms = AllocMemoryStream(); + var temp = new CodedOutputStream(ms); + action(temp); temp.Flush(); ms.Seek(0, SeekOrigin.Begin); var bs = ByteString.FromStream(ms); @@ -228,6 +238,24 @@ namespace Luban.Job.Cfg.DataExporters FreeMemoryStream(ms); } + public void Accept(DBean type, CodedOutputStream x) + { + EnterScope(x, cos => + { + var bean = type.Type; + + if (bean.IsAbstractType) + { + cos.WriteTag(type.ImplType.AutoId, WireFormat.WireType.LengthDelimited); + EnterScope(cos, cos2 => WriteRawMessageWithoutLength(type, cos2)); + } + else + { + WriteRawMessageWithoutLength(type, cos); + } + }); + } + private void WriteList(TType elementType, int fieldId, List datas, CodedOutputStream x) { if (elementType.Apply(IsProtobufPackedType.Ins)) diff --git a/src/Luban.Server/Templates/config/pb2/all.tpl b/src/Luban.Server/Templates/config/pb2/all.tpl index 27aa13c..9a69d18 100644 --- a/src/Luban.Server/Templates/config/pb2/all.tpl +++ b/src/Luban.Server/Templates/config/pb2/all.tpl @@ -1,4 +1,7 @@ syntax = "proto2"; + +package {{x.namespace}}; + // luban internal types begin message Vector2 { required float x = 1;