public static void Write(IBinaryWriter o, Kernel.Config.ConfigHeader d) { o.Write(d != null); if (d == null) { return; } o.Write(d.BodySize); ArrayPoli_FieldLayoutSerializer.Write(o, d.Contents); o.Write(d.HeaderSize); }
public static Kernel.Config.ConfigHeader Read(IBinaryReader o, Kernel.Config.ConfigHeader d) { if (o.ReadBoolean() == false) { return(null); } if (d == null) { d = new Kernel.Config.ConfigHeader(); } d.BodySize = o.ReadInt32(); d.Contents = ArrayPoli_FieldLayoutSerializer.Read(o, d.Contents as Kernel.Config.FieldLayout[]); d.HeaderSize = o.ReadInt32(); return(d); }
public void WriteToBinary(BinWriter writer) { using (MemoryStream bodyStream = new MemoryStream()) using (BinWriter bodyWriter = new BinWriter(bodyStream)) { writer.Write(Hash); if (Fields == null) { return; } ConfigHeader header = new ConfigHeader(); header.Contents = new FieldLayout[Fields.Length]; for (int i = 0; i < Fields.Length; i++) { var f = Fields[i]; int offset = (int)bodyWriter.BaseStream.Position; var elemSerializer = Serializers[f.ElemType]; if (f.FieldMode == ConfigFieldInfo.Mode.CONST) { header.Contents[i] = FieldLayout.CreateFieldLayout(f.FieldMode, offset, null); object obj = ConfigManager.Instance.GetConfig(f.ElemType); elemSerializer.Write(bodyWriter, obj); } else { var dict = (IDictionary)ConfigManager.Instance.GetConfig(f.ElemType); if (dict == null) { dict = TypeUtil.CreateInstance(f.ConfigType) as IDictionary; } var layout = header.Contents[i] = FieldLayout.CreateFieldLayout(f.FieldMode, offset, TypeUtil.GetDictionaryKeyType(dict.GetType())); var e = dict.GetEnumerator(); while (e.MoveNext()) { layout.Add(e.Key, (int)bodyWriter.BaseStream.Position); elemSerializer.Write(bodyWriter, e.Value); } layout.Size = (int)bodyWriter.BaseStream.Position - offset; } } using (var headerStream = new MemoryStream()) using (var headerWriter = new BinWriter(headerStream)) { Serializers[typeof(ConfigHeader)].Write(headerWriter, header); header.HeaderSize = (int)headerWriter.BaseStream.Position; header.BodySize = (int)bodyWriter.BaseStream.Position; Serializers[typeof(ConfigHeader)].Write(writer, header); writer.Write(bodyStream.GetBuffer()); } } }