Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. |

Expand Down
18 changes: 18 additions & 0 deletions src/TdbIO/DbvDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ internal DbvDocument(IReadOnlyList<string> warnings, string name, IReadOnlyList<
/// <summary>The name stored after the signature, printable ASCII.</summary>
public string Name { get; }

/// <summary>The domain identifier of the database (from <see cref="Prologue"/> word 1: 2 for options, 3 for environment, 4 for analysis).</summary>
public uint DomainId => Prologue[1];

/// <summary>The generation/version number of the domain file (from <see cref="ListHeader"/> word 3), equals <c>GuidRecords.Count + 1</c>.</summary>
public uint Generation => ListHeader[3];

/// <summary>The base byte offset of domain events (alias for <see cref="B"/>).</summary>
public uint BaseOffset => B;

/// <summary>The domain event level (alias for <see cref="C"/>; expected to be 5).</summary>
public uint EventLevel => C;

/// <summary>The current byte offset after domain events (from <see cref="T"/> word 1; equals <c>BaseOffset + 32 * L1.Count</c>).</summary>
public uint CurrentOffset => T[1];

/// <summary>The byte offset of the last domain event (from <see cref="T"/> word 4; equals <c>CurrentOffset - 32</c>).</summary>
public uint LastEventOffset => T[4];

/// <summary>The six raw numbers after the name.</summary>
public IReadOnlyList<uint> Prologue { get; }

Expand Down
2 changes: 2 additions & 0 deletions src/TdbIO/Internal/DbvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public static DbvDocument Read(byte[] payload, List<string> 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;

Expand Down
10 changes: 10 additions & 0 deletions tests/TdbIO.Tests/DbvTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -220,6 +226,8 @@ public void BytesAfterTheC9RecordsMustBeSections()
[InlineData("A2")]
[InlineData("C")]
[InlineData("T1")]
[InlineData("T2")]
[InlineData("T3")]
[InlineData("T4")]
[InlineData("R")]
[InlineData("RowType")]
Expand All @@ -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;
Expand Down
Loading