public static TightCapability Deserialize(Stream stream) { var reader = new Util.BinaryReader(stream); return(new TightCapability() { Code = reader.ReadInt32(), Vendor = reader.ReadString(4), Signature = reader.ReadString(8) }); }
private static DatapointDatabase Open(string path, Stream stream, Func <DateTime> currentTimeProvider = null) { using (var binaryReader = new Util.BinaryReader(stream, Encoding.UTF8, true)) { var signature = binaryReader.ReadBytes(Signature.Length); if (!signature.SequenceEqual(Signature)) { throw new DatabaseException("Incompatible Statsify Database format"); } var major = binaryReader.ReadByte(); var minor = binaryReader.ReadByte(); var version = new Version(major, minor); if (version != new Version(1, 0)) { throw new DatabaseException("Incompatible Statsify Database version"); } var dowsamplingMethod = (DownsamplingMethod)binaryReader.ReadInt32(); var downsamplingFactor = binaryReader.ReadSingle(); var maxRetention = binaryReader.ReadInt32(); var archivesLength = binaryReader.ReadInt32(); var archives = new List <Archive>(); for (var i = 0; i < archivesLength; ++i) { var offset = binaryReader.ReadInt32(); var precision = binaryReader.ReadInt32(); var history = binaryReader.ReadInt32(); archives.Add(new Archive(offset, history * DatapointSize, new Retention(TimeSpan.FromSeconds(precision), history))); } // for return(new DatapointDatabase(path, downsamplingFactor, dowsamplingMethod, maxRetention, archives, currentTimeProvider)); } // using }