【修复】修复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);
}
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<CodedOutputStream> 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<DType> datas, CodedOutputStream x)
{
if (elementType.Apply(IsProtobufPackedType.Ins))

View File

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