public void Align16_long() { Aver.AreEqual(16, IntMath.Align16(3L)); Aver.AreEqual(48, IntMath.Align16(33L)); Aver.AreEqual(0, IntMath.Align16(0L)); Aver.AreEqual(16, IntMath.Align16(8L)); Aver.AreEqual(16, IntMath.Align16(16L)); Aver.AreEqual(32, IntMath.Align16(17L)); Aver.AreEqual(128, IntMath.Align16(127L)); Aver.AreEqual(128, IntMath.Align16(128L)); Aver.AreEqual(144, IntMath.Align16(129L)); Aver.AreEqual(0, IntMath.Align16(-5L)); Aver.AreEqual(-16, IntMath.Align16(-17L)); }
public void Align16_int() { Aver.AreEqual(16, IntMath.Align16(3)); Aver.AreEqual(48, IntMath.Align16(33)); Aver.AreEqual(0, IntMath.Align16(0)); Aver.AreEqual(16, IntMath.Align16(8)); Aver.AreEqual(16, IntMath.Align16(16)); Aver.AreEqual(32, IntMath.Align16(17)); Aver.AreEqual(128, IntMath.Align16(127)); Aver.AreEqual(128, IntMath.Align16(128)); Aver.AreEqual(144, IntMath.Align16(129)); Aver.AreEqual(0, IntMath.Align16(-5)); Aver.AreEqual(-16, IntMath.Align16(-17)); }
private static Type readHeader(Stream stream) { var buf = Format.getBuff32(); Format.readFromStream(stream, buf, Format.HEADER_BUF.Length); for (var i = 0; i < Format.HEADER_BUF.Length; i++) { if (buf[i] != Format.HEADER_BUF[i]) { throw new BinLogException(StringConsts.BINLOG_STREAM_CORRUPTED_ERROR + "bad header"); } } var tn = Format.ReadString(stream); if (tn.IsNullOrWhiteSpace()) { throw new BinLogException(StringConsts.BINLOG_STREAM_CORRUPTED_ERROR + "bad type"); } var pos = stream.Position; var start = IntMath.Align16(pos); while (pos < start) { if (Format.ReadByte(stream) != 0) { throw new BinLogException(StringConsts.BINLOG_STREAM_CORRUPTED_ERROR + "bad header pad"); } } var result = Type.GetType(tn, false); if (result == null || !typeof(LogReader).IsAssignableFrom(result)) { throw new BinLogException(StringConsts.BINLOG_BAD_READER_TYPE_ERROR + tn); } return(result); }
public IEnumerable <object> read(bool includeMetadata) { DateTime current = MiscUtils.UNIX_EPOCH_START_DATE; while (App.Active) { while (App.Active) { var h = Format.TryReadPageHeader(m_Stream, ref current); if (h == Format.PageHeaderReadStatus.OK) { break; } if (h == Format.PageHeaderReadStatus.EOF) { yield break; } var pos = Stream.Position; var newPos = IntMath.Align16(pos); var delta = newPos - pos; var eof = true; try { if (delta > 0) { Stream.Seek(delta, SeekOrigin.Current); } eof = false; } catch {} if (eof) { yield break; } }//page while (App.Active) { byte rec = Format.REC_INVALID; try{ rec = Format.ReadByte(m_Stream); } catch {} if (rec == Format.REC_EOF) { break; } else if (rec == Format.REC_TIMESTAMP) { DateTime ts = DateTime.MinValue; try{ ts = Format.ReadTimeStamp(m_Stream); } catch {} if (ts <= MiscUtils.UNIX_EPOCH_START_DATE || ts < current)//corruption { if (includeMetadata) { yield return(LogCorruption.Instance); } break; } current = ts; if (includeMetadata) { yield return(new LogUTCTimeStamp(ts)); } } else if (rec == Format.REC_SERIALIZER) { //todo deserialize } else { if (includeMetadata) { yield return(LogCorruption.Instance); } break; } } //records } //outer }