protobuf-net ライブラリの使用を開始しました。シリアル化の速度が 30% 向上しましたが、結果のファイル サイズに問題があります。
私のデータモデルは次のとおりです。
[Serializable]
[ProtoContract(SkipConstructor = true)]
private class ReportDataItem
{
[ProtoMember(1)]
public Int32 C11 { get; set; }
[ProtoMember(2)]
public Int32 C12 { get; set; }
[ProtoMember(3)]
public Int32 C13 { get; set; }
[ProtoMember(4)]
public Int32 C14 { get; set; }
[ProtoMember(5)]
public Int32 C15 { get; set; }
[ProtoMember(6)]
public Int32 C16 { get; set; }
[ProtoMember(7)]
public Int32 C17 { get; set; }
[ProtoMember(8)]
public Int32 C18 { get; set; }
[ProtoMember(9)]
public Int32 C19 { get; set; }
[ProtoMember(10)]
public Int32 C110 { get; set; }
[ProtoMember(11)]
public Int64 C21 { get; set; }
[ProtoMember(12)]
public Int64 C22 { get; set; }
[ProtoMember(13)]
public Int64 C23 { get; set; }
[ProtoMember(14)]
public Int64 C24 { get; set; }
[ProtoMember(15)]
public Int64 C25 { get; set; }
[ProtoMember(16)]
public Int64 C26 { get; set; }
[ProtoMember(17)]
public Int64 C27 { get; set; }
[ProtoMember(18)]
public Int64 C28 { get; set; }
[ProtoMember(19)]
public Int64 C29 { get; set; }
[ProtoMember(20)]
public Int64 C210 { get; set; }
[ProtoMember(21)]
public String C31 { get; set; }
[ProtoMember(22)]
public String C32 { get; set; }
[ProtoMember(23)]
public String C33 { get; set; }
[ProtoMember(24)]
public String C34 { get; set; }
[ProtoMember(25)]
public String C35 { get; set; }
[ProtoMember(26)]
public String C36 { get; set; }
[ProtoMember(27)]
public String C37 { get; set; }
[ProtoMember(28)]
public String C38 { get; set; }
[ProtoMember(29)]
public String C39 { get; set; }
[ProtoMember(30)]
public String C310 { get; set; }
}
[Serializable]
[ProtoContract()]
private class ReportData
{
[ProtoMember(1, DataFormat = DataFormat.Group)]
public List<ReportDataItem> ReportDataItems { get; set; }
}
[Serializable]
[ProtoContract()]
private class Report
{
[ProtoMember(1)]
public ReportData ReportData { get; set; }
}
したがって、シリアル化しようとすると:
private static void ObjectSerialization()
{
const string someData = @"qtwretyfsjdabvfsjdlfudspogds;kfg;lkfdsl;gkl;dsfkgl;kdfsgr;iweprpo\z\xlvcfmxzcbvjiorsdifdlf\jl;dsa";
Report report = new Report();
report.ReportData = new ReportData {ReportDataItems = new List<ReportDataItem>()};
for (int j = 0; j < 10; j++)
{
ReportDataItem reportDataItem = new ReportDataItem();
reportDataItem.C11 = j;
reportDataItem.C12 = j;
reportDataItem.C13 = j;
reportDataItem.C14 = j;
reportDataItem.C15 = j;
reportDataItem.C16 = j;
reportDataItem.C17 = j;
reportDataItem.C18 = j;
reportDataItem.C19 = j;
reportDataItem.C110 = j;
reportDataItem.C21 = j;
reportDataItem.C22 = j;
reportDataItem.C23 = j;
reportDataItem.C24 = j;
reportDataItem.C25 = j;
reportDataItem.C26 = j;
reportDataItem.C27 = j;
reportDataItem.C28 = j;
reportDataItem.C29 = j;
reportDataItem.C210 = j;
reportDataItem.C31 =someData;
reportDataItem.C32 = someData;
reportDataItem.C33 = someData;
reportDataItem.C34 = someData;
reportDataItem.C35 = someData;
reportDataItem.C36 = someData;
reportDataItem.C37 = someData;
reportDataItem.C38 = someData;
reportDataItem.C39 = someData;
reportDataItem.C310 = someData;
report.ReportData.ReportDataItems.Add(reportDataItem);
}
using (Stream stream = new FileStream(@"c:\Test\Object\0.bin", FileMode.Create, FileAccess.Write, FileShare.Write))
{
Serializer.Serialize(stream, report);
}
using (Stream stream = new FileStream(@"c:\Test\Object\bf_0.bin", FileMode.Create, FileAccess.Write, FileShare.Write))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, report);
}
}
以下に結果を示しました。
- protobuf-netファイル サイズ10428 バイト
- BinaryFormatterファイル サイズ3458 バイト
結果のprotobuf-netファイルのサイズを減らすための適切な解決策を見つけるのを手伝ってくれませんか. Protobuf-net VS Package Manager からパッケージとしてインストールしました。