diff --git a/docs/public-api.md b/docs/public-api.md index 4949dd6..ceb7c03 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -82,7 +82,7 @@ offset or line number. A warning never contains text from the file. Warnings are | --- | --- | | `TableSection` | A section of fixed-size rows, from `Db1Document.ReadTables()` or `DbvDocument.Sections`. `Ordinal`, `Offset`, `End`, `Key` (schema table number in `.db1`, else null), `RowSize`, `Descriptors` (primary and secondary index specifications), `RowsOffset` and `Rows`. `Rows` is a view over the data: a row is built when it is read. | | `TableRow` | `Offset` (of the marker byte), `Marker` (0x04 active, 0x0C deleted/superseded in `.db1`), `Body` (`RowSize` raw bytes), `A` / `CreationTimeId` (creation transaction TimeId) and `B` / `DeletionTimeId` (deletion or superseding transaction TimeId). `IsActive` and `IsDeleted` inspect the marker. | -| `DbvDocument` | A DBV@ file: `Name`, `Prologue`, `ListHeader`, `GuidRecords`, `B`, `C`, `L1`, `L2`, `T`, `C9Records`, `Sections` and `Payload`. The numbers are raw; their names are positions, not meanings. | +| `DbvDocument` | A DBV@ file: `Name`, `DomainId` (`Prologue[1]`), `Generation` (`ListHeader[3]`), `BaseOffset` (`B`), `EventLevel` (`C`), `CurrentOffset` (`T[1]`), `LastEventOffset` (`T[4]`), `Prologue`, `ListHeader`, `GuidRecords`, `B`, `C`, `L1`, `L2`, `T`, `C9Records`, `Sections` and `Payload`. The raw numbers are preserved; named aliases identify the domain, generation and event offsets. | | `DbvGuidRecord` | `Value` (raw), `Index` (1-based, checked against the position) and `Id`. | | `DbvC9Record` | A record that starts with `C9 C0 CE DB`: four raw numbers `R0` to `R3`. | diff --git a/src/TdbIO/DbvDocument.cs b/src/TdbIO/DbvDocument.cs index 654b5ee..726b951 100644 --- a/src/TdbIO/DbvDocument.cs +++ b/src/TdbIO/DbvDocument.cs @@ -29,6 +29,24 @@ internal DbvDocument(IReadOnlyList warnings, string name, IReadOnlyList< /// The name stored after the signature, printable ASCII. public string Name { get; } + /// The domain identifier of the database (from word 1: 2 for options, 3 for environment, 4 for analysis). + public uint DomainId => Prologue[1]; + + /// The generation/version number of the domain file (from word 3), equals GuidRecords.Count + 1. + public uint Generation => ListHeader[3]; + + /// The base byte offset of domain events (alias for ). + public uint BaseOffset => B; + + /// The domain event level (alias for ; expected to be 5). + public uint EventLevel => C; + + /// The current byte offset after domain events (from word 1; equals BaseOffset + 32 * L1.Count). + public uint CurrentOffset => T[1]; + + /// The byte offset of the last domain event (from word 4; equals CurrentOffset - 32). + public uint LastEventOffset => T[4]; + /// The six raw numbers after the name. public IReadOnlyList Prologue { get; } diff --git a/src/TdbIO/Internal/DbvReader.cs b/src/TdbIO/Internal/DbvReader.cs index 5e08f50..ac6d2fc 100644 --- a/src/TdbIO/Internal/DbvReader.cs +++ b/src/TdbIO/Internal/DbvReader.cs @@ -75,6 +75,8 @@ public static DbvDocument Read(byte[] payload, List warnings) if (t[0] != listHeader[3]) throw FormatError.At(Invariant($"DBV@ word T[0] = {t[0]} differs from the record count word A[3] = {listHeader[3]}"), p); Expect(warnings, t[1] == b + 32L * listLength, "word T[1]", p + 4); + Expect(warnings, t[2] == 0, "word T[2]", p + 8); + Expect(warnings, t[3] == 0, "word T[3]", p + 12); Expect(warnings, t[4] == t[1] - 32L, "word T[4]", p + 16); p += 24; diff --git a/tests/TdbIO.Tests/DbvTests.cs b/tests/TdbIO.Tests/DbvTests.cs index 93d67c9..d9ce068 100644 --- a/tests/TdbIO.Tests/DbvTests.cs +++ b/tests/TdbIO.Tests/DbvTests.cs @@ -31,10 +31,16 @@ public void FileWithoutSectionsIsRead() Assert.Equal(new DbvGuidRecord(100, 1, new Guid("03020100-0504-0706-0809-0a0b0c0d0e0f")), doc.GuidRecords[0]); Assert.Equal(new DbvGuidRecord(1, 2, new Guid("43424140-4544-4746-4849-4a4b4c4d4e4f")), doc.GuidRecords[1]); Assert.Equal(0x400u, doc.B); + Assert.Equal(0x400u, doc.BaseOffset); Assert.Equal(5u, doc.C); + Assert.Equal(5u, doc.EventLevel); + Assert.Equal(7u, doc.DomainId); + Assert.Equal(3u, doc.Generation); Assert.Equal(new uint[] { 1, 2 }, doc.L1); Assert.Equal(new[] { 32, -32 }, doc.L2); Assert.Equal(new uint[] { 3, 0x440, 0, 0, 0x420, 2 }, doc.T); + Assert.Equal(0x440u, doc.CurrentOffset); + Assert.Equal(0x420u, doc.LastEventOffset); Assert.Equal(new[] { new DbvC9Record(0, 1, 0, -1), new DbvC9Record(0, 1, 0, -1) }, doc.C9Records); Assert.Empty(doc.Sections); Assert.Equal(data, doc.Payload.ToArray()); @@ -220,6 +226,8 @@ public void BytesAfterTheC9RecordsMustBeSections() [InlineData("A2")] [InlineData("C")] [InlineData("T1")] + [InlineData("T2")] + [InlineData("T3")] [InlineData("T4")] [InlineData("R")] [InlineData("RowType")] @@ -236,6 +244,8 @@ public void UnusualValuesAreKeptWithAWarning(string field) case "A2": parts.ListHeader = [0, 1, 14, 3]; break; case "C": parts.C = 6; break; case "T1": parts.T = [3, 0x500, 0, 0, 0x4E0, 2]; break; + case "T2": parts.T = [3, 0x440, 1, 0, 0x420, 2]; break; + case "T3": parts.T = [3, 0x440, 0, 1, 0x420, 2]; break; case "T4": parts.T = [3, 0x440, 0, 0, 0x400, 2]; break; case "R": parts.C9[0] = (0xDBCEC0C9, [0, 1, 0, -2]); break; case "RowType": parts.Sections = [DbvSection(1, [1], (3, [0], 0x401, 0x401))]; break;