【修复】修复cfg data_protobuf导出多态结构数据的问题。已经通过所有测试。完美!

main
walon 2021-11-30 10:32:47 +08:00
parent 6e83d8c1eb
commit 56c222976e
2 changed files with 40 additions and 9 deletions

View File

@ -166,16 +166,14 @@ namespace Luban.Job.Cfg.DataExporters
FreeMemoryStream(ms); FreeMemoryStream(ms);
} }
public void Accept(DBean type, CodedOutputStream x) private void WriteRawMessageWithoutLength(DBean type, CodedOutputStream temp)
{ {
var bean = type.Type; //var ms = AllocMemoryStream();
if (bean.IsAbstractType) //var temp = new CodedOutputStream(ms);
{ //if (bean.IsAbstractType)
x.WriteTag(type.ImplType.AutoId, WireFormat.WireType.LengthDelimited); //{
} // temp.WriteTag(type.ImplType.AutoId, WireFormat.WireType.LengthDelimited);
//}
var ms = AllocMemoryStream();
var temp = new CodedOutputStream(ms);
var defFields = type.ImplType.HierarchyFields; var defFields = type.ImplType.HierarchyFields;
int index = 0; 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<CodedOutputStream> action)
{
var ms = AllocMemoryStream();
var temp = new CodedOutputStream(ms);
action(temp);
temp.Flush(); temp.Flush();
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
var bs = ByteString.FromStream(ms); var bs = ByteString.FromStream(ms);
@ -228,6 +238,24 @@ namespace Luban.Job.Cfg.DataExporters
FreeMemoryStream(ms); 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<DType> datas, CodedOutputStream x) private void WriteList(TType elementType, int fieldId, List<DType> datas, CodedOutputStream x)
{ {
if (elementType.Apply(IsProtobufPackedType.Ins)) if (elementType.Apply(IsProtobufPackedType.Ins))

View File

@ -1,4 +1,7 @@
syntax = "proto2"; syntax = "proto2";
package {{x.namespace}};
// luban internal types begin // luban internal types begin
message Vector2 { message Vector2 {
required float x = 1; required float x = 1;