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;