public FrugalQuantile Deserialize(Stream stream) { using (var br = new BinaryReader(stream)) { int dataFormatMajorVersion = br.ReadUInt16(); int dataFormatMinorVersion = br.ReadUInt16(); AssertDataVersionCanBeRead(dataFormatMajorVersion, dataFormatMinorVersion); var quantile = br.ReadDouble(); var estimate = br.ReadDouble(); ICollection <double> directCount = null; var direct = br.ReadBoolean(); if (direct) { int count = br.ReadInt32(); directCount = new List <double>(); for (var i = 0; i < count; i++) { var element = br.ReadDouble(); directCount.Add(element); } } var data = new FrugalState { DirectCount = directCount, Estimate = estimate, Quantile = quantile }; var result = new FrugalQuantile(data); return(result); } }
public void Serialize(Stream stream, FrugalQuantile estimator) { using (var bw = new BinaryWriter(stream)) { bw.Write(DataFormatMajorVersion); bw.Write(DataFormatMinorVersion); var data = estimator.GetState(); bw.Write(data.Quantile); bw.Write(data.Estimate); bw.Write(data.DirectCount != null ? true : false); if (data.DirectCount != null) { bw.Write(data.DirectCount.Count); foreach (var element in data.DirectCount) { bw.Write(element); } } bw.Flush(); } }