Skip to content
Open
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ API between minor releases.
HTML exports of `tdbio` warn on standard error how many parts are rectangular proxy boxes, and the last two also list
the findings. The warnings are not part of the exported data.

### Breaking

- `DbvDocument`: the raw fields `B`, `C`, `L1`, `L2`, `T` and `EventLevel` are removed. The offsets of the domain
events stay as `BaseOffset`, `CurrentOffset` and `LastEventOffset`; the reader checks every other raw value
against the ones always seen and reports deviations in `Warnings`, and `Payload` holds the raw bytes. Raw values
of unknown meaning are named by byte offset everywhere (`Db1Document.IdMapField65` and `IdMapField73`).

### Changed

- The IFC output of the object model is kept apart from the native engine in `src/TdbIO/Ifc`. With
Expand All @@ -45,7 +52,6 @@ API between minor releases.
- The DSTV NC reader and the template lexer stream their lines and tokens instead of holding them as lists.
- The gzip reader takes the unpacked size in the trailer as the initial size of its buffer.
- Text rows with marker `0x0C` are rejected; only `0x04` was seen in text sections.

### Fixed

- The text values of table rows are no longer required to be UTF-8. They are single-byte in the code page of the system
Expand Down
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. Typed bulk decoders (`AsObjects()`, `AsParts()`, `AsPoints()`, etc.) decode all rows into typed record structs. |
| `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. `TextEncoding`: the encoding the typed decoders read the text values with, the `TdbReadOptions.TextEncoding` the file was opened with or null. Typed decoders (`AsObject()`, `AsPart()`, `AsPoint()`, etc.) decode the row body into typed record structs. |
| `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. |
| `DbvDocument` | A DBV@ file: `Name`, `DomainId` (`Prologue[1]`), `Generation` (`ListHeader[3]`), `BaseOffset`, `CurrentOffset` and `LastEventOffset` (the byte offsets of the domain events, checked against the relations the files always keep), `Prologue`, `ListHeader`, `GuidRecords`, `C9Records`, `Sections` and `Payload`. Raw values whose meaning is not known are not separate properties: the reader checks them against the values always seen, reports deviations in `Warnings`, and `Payload` holds the raw bytes. |
| `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
76 changes: 76 additions & 0 deletions src/TdbIO/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Intentional removals of issue #11: the raw DBV@ fields B, C, L1, L2 and T are gone from DbvDocument.
When version 0.2.0 ships, PackageValidationBaselineVersion moves to it and this file can shrink. -->
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_B</Target>
<Left>lib/net10.0/TdbIO.dll</Left>
<Right>lib/net10.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_C</Target>
<Left>lib/net10.0/TdbIO.dll</Left>
<Right>lib/net10.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_L1</Target>
<Left>lib/net10.0/TdbIO.dll</Left>
<Right>lib/net10.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_L2</Target>
<Left>lib/net10.0/TdbIO.dll</Left>
<Right>lib/net10.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_T</Target>
<Left>lib/net10.0/TdbIO.dll</Left>
<Right>lib/net10.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_B</Target>
<Left>lib/net8.0/TdbIO.dll</Left>
<Right>lib/net8.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_C</Target>
<Left>lib/net8.0/TdbIO.dll</Left>
<Right>lib/net8.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_L1</Target>
<Left>lib/net8.0/TdbIO.dll</Left>
<Right>lib/net8.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_L2</Target>
<Left>lib/net8.0/TdbIO.dll</Left>
<Right>lib/net8.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:TdbIO.DbvDocument.get_T</Target>
<Left>lib/net8.0/TdbIO.dll</Left>
<Right>lib/net8.0/TdbIO.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
49 changes: 16 additions & 33 deletions src/TdbIO/DbvDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
namespace TdbIO;

/// <summary>A gzip file whose content starts with <c>DBV@</c>: a name, a GUID list, a few lists of numbers and table
/// sections. Most numbers have no known meaning and are given raw; values that differ from the ones always seen are kept
/// and reported in <see cref="TdbDocument.Warnings"/>.</summary>
/// sections. Raw values whose meaning is not known are not separate properties: the reader checks each of them against
/// the values always seen, reports deviations in <see cref="TdbDocument.Warnings"/>, and <see cref="Payload"/> holds
/// the raw bytes.</summary>
public sealed class DbvDocument : TdbDocument
{
internal DbvDocument(IReadOnlyList<string> warnings, string name, IReadOnlyList<uint> prologue, IReadOnlyList<uint> listHeader,
IReadOnlyList<DbvGuidRecord> guidRecords, uint b, uint c, IReadOnlyList<uint> l1, IReadOnlyList<int> l2, IReadOnlyList<uint> t,
IReadOnlyList<DbvGuidRecord> guidRecords, uint baseOffset, uint currentOffset, uint lastEventOffset,
IReadOnlyList<DbvC9Record> c9Records, IReadOnlyList<TableSection> sections, ReadOnlyMemory<byte> payload)
: base(TdbFileKind.Dbv, warnings)
{
Name = name;
Prologue = prologue;
ListHeader = listHeader;
GuidRecords = guidRecords;
B = b;
C = c;
L1 = l1;
L2 = l2;
T = t;
BaseOffset = baseOffset;
CurrentOffset = currentOffset;
LastEventOffset = lastEventOffset;
C9Records = c9Records;
Sections = sections;
Payload = payload;
Expand All @@ -36,17 +35,17 @@ internal DbvDocument(IReadOnlyList<string> warnings, string name, IReadOnlyList<
/// <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 base byte offset of the domain events: the row enders of the sections lie inside the interval that
/// starts here and ends at <see cref="CurrentOffset"/>. The raw word is checked to be a multiple of 32.</summary>
public uint BaseOffset { get; }

/// <summary>The domain event level (alias for <see cref="C"/>; expected to be 5).</summary>
public uint EventLevel => C;
/// <summary>The byte offset after the domain events, which the reader checks to equal
/// <c>BaseOffset + 32 · K</c> for the length <c>K</c> stored before the lists.</summary>
public uint CurrentOffset { get; }

/// <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 byte offset of the last domain event, which the reader checks to equal
/// <c>CurrentOffset − 32</c>.</summary>
public uint LastEventOffset { get; }

/// <summary>The six raw numbers after the name.</summary>
public IReadOnlyList<uint> Prologue { get; }
Expand All @@ -57,22 +56,6 @@ internal DbvDocument(IReadOnlyList<string> warnings, string name, IReadOnlyList<
/// <summary>The GUID records in file order.</summary>
public IReadOnlyList<DbvGuidRecord> GuidRecords { get; }

/// <summary>The raw number after the GUID records.</summary>
public uint B { get; }

/// <summary>The raw number after <see cref="B"/>.</summary>
public uint C { get; }

/// <summary>The first list of raw numbers; its length is stored before it.</summary>
public IReadOnlyList<uint> L1 { get; }

/// <summary>The second list of raw numbers, signed, as long as <see cref="L1"/>.</summary>
public IReadOnlyList<int> L2 { get; }

/// <summary>The six raw numbers after the lists. The first one equals the last number of <see cref="ListHeader"/>;
/// the last one is the number of <see cref="C9Records"/>.</summary>
public IReadOnlyList<uint> T { get; }

/// <summary>The records that start with <c>C9 C0 CE DB</c>.</summary>
public IReadOnlyList<DbvC9Record> C9Records { get; }

Expand Down
3 changes: 1 addition & 2 deletions src/TdbIO/Internal/DbvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public static DbvDocument Read(byte[] payload, List<string> warnings, Encoding?

var sections = SectionWalker.Walk(payload, (int)p, 0, SectionMode.Dbv, warnings, textEncoding);
return new DbvDocument(warnings.AsReadOnly(), name, Array.AsReadOnly(prologue), Array.AsReadOnly(listHeader),
Array.AsReadOnly(records), b, c, Array.AsReadOnly(l1), Array.AsReadOnly(l2), Array.AsReadOnly(t), Array.AsReadOnly(c9),
sections, payload);
Array.AsReadOnly(records), b, t[1], t[4], Array.AsReadOnly(c9), sections, payload);
}

private static uint[] ReadU32s(ReadOnlySpan<byte> d, long at, int count)
Expand Down
4 changes: 3 additions & 1 deletion src/TdbIO/TdbIO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
<AssemblyName>TdbIO</AssemblyName>
<PackageId>TdbIO</PackageId>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- dotnet pack compares the public API of both target frameworks with the last published release. -->
<!-- dotnet pack compares the public API of both target frameworks with the last published release.
The suppressions name the removals of issue #11; move the baseline to 0.2.0 when that version ships. -->
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>0.1.0</PackageValidationBaselineVersion>
<ApiCompatSuppressionFile>$(MSBuildProjectDirectory)\CompatibilitySuppressions.xml</ApiCompatSuppressionFile>
</PropertyGroup>

<!-- The native engine is everything except the target-format output in Ifc. CI compiles it together with the scene
Expand Down
10 changes: 2 additions & 8 deletions tests/TdbIO.Tests/DbvTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ public void FileWithoutSectionsIsRead()
Assert.Equal(2, doc.GuidRecords.Count);
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);
Expand Down Expand Up @@ -144,8 +138,9 @@ public void RecordCountWordOneMeansNoRecords()
{
var doc = DbvDocument.Create(new DbvParts { Records = [] }.Build());
Assert.Empty(doc.GuidRecords);
// The reader fails the whole file when the tail word T[0] differs from the record count word A[3], so a
// successful read implies T[0] = 1 here.
Assert.Equal(1u, doc.ListHeader[3]);
Assert.Equal(1u, doc.T[0]);
}

[Fact]
Expand Down Expand Up @@ -254,7 +249,6 @@ public void UnusualValuesAreKeptWithAWarning(string field)
string warning = Assert.Single(doc.Warnings);
Assert.Contains("offset 0x", warning);
Assert.DoesNotContain("Secret", warning);
if (field == "C") Assert.Equal(6u, doc.C);
if (field == "R") Assert.Equal(-2, doc.C9Records[0].R3);
}

Expand Down
1 change: 0 additions & 1 deletion tests/TdbIO.Tests/SampleTests.Tables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void EveryDbvFileOpens()
var doc = DbvDocument.Create(Gzip.Unpack(File.ReadAllBytes(file), TablesReadLimit));
long end = doc.Sections.Count > 0 ? doc.Sections[^1].End : -1;
if (doc.Sections.Count > 0 && end != doc.Payload.Length) failures.Add($"{at}: the sections do not end at the end of the data");
if (doc.T[0] != doc.ListHeader[3]) failures.Add($"{at}: T[0] differs from A[3]");
for (int i = 0; i < doc.GuidRecords.Count; i++)
if (doc.GuidRecords[i].Index != i + 1) failures.Add($"{at}: GUID record {i + 1} has another index");
foreach (string warning in doc.Warnings) output.WriteLine($"{at}: warning: {warning}");
Expand Down
25 changes: 17 additions & 8 deletions tests/TdbIO.Tests/VectorTests.Tables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,21 @@ public void DbvFileVectorsParseAsExpected()
Assert.True(string.Equals(guid.GetProperty("bytes").GetString(), Convert.ToHexString(r.Id.ToByteArray()), StringComparison.OrdinalIgnoreCase),
$"{name}: guid record {i} bytes");
}
Assert.True(expected.GetProperty("B").GetUInt32() == doc.B, $"{name}: B");
Assert.True(expected.GetProperty("C").GetUInt32() == doc.C, $"{name}: C");
Assert.True(expected.GetProperty("K").GetInt32() == doc.L1.Count, $"{name}: K");
Assert.True(TableJson.UInts(expected.GetProperty("L1")).SequenceEqual(doc.L1), $"{name}: L1");
Assert.True(TableJson.Ints(expected.GetProperty("L2")).SequenceEqual(doc.L2), $"{name}: L2");
Assert.True(TableJson.UInts(expected.GetProperty("T")).SequenceEqual(doc.T), $"{name}: T");
// The raw words B, C, K, L1, L2 and T are read back from the payload: the API no longer exposes them, and
// the reader checks their relations against the values always seen. The marker offset is computed above.
int bOff = marker + 20 + 24 * doc.GuidRecords.Count;
uint ReadU32(int at) => BinaryPrimitives.ReadUInt32LittleEndian(doc.Payload.Span.Slice(at, 4));
Assert.True(expected.GetProperty("B").GetUInt32() == doc.BaseOffset, $"{name}: B");
Assert.True(expected.GetProperty("B").GetUInt32() == ReadU32(bOff), $"{name}: B in the payload");
Assert.True(expected.GetProperty("C").GetUInt32() == ReadU32(bOff + 4), $"{name}: C");
int k = (int)ReadU32(bOff + 8);
Assert.True(expected.GetProperty("K").GetInt32() == k, $"{name}: K");
var l1 = Enumerable.Range(0, k).Select(i => ReadU32(bOff + 12 + 4 * i)).ToArray();
Assert.True(TableJson.UInts(expected.GetProperty("L1")).SequenceEqual(l1), $"{name}: L1");
var l2 = Enumerable.Range(0, k).Select(i => (int)ReadU32(bOff + 12 + 4 * k + 4 * i)).ToArray();
Assert.True(TableJson.Ints(expected.GetProperty("L2")).SequenceEqual(l2), $"{name}: L2");
var t = Enumerable.Range(0, 6).Select(i => ReadU32(bOff + 12 + 8 * k + 4 * i)).ToArray();
Assert.True(TableJson.UInts(expected.GetProperty("T")).SequenceEqual(t), $"{name}: T");
var c9 = expected.GetProperty("c9_records").EnumerateArray().Select(r => TableJson.Ints(r).ToArray()).ToList();
Assert.True(c9.Count == doc.C9Records.Count, $"{name}: c9_records");
for (int i = 0; i < c9.Count; i++)
Expand All @@ -275,12 +284,12 @@ public void DbvFileVectorsParseAsExpected()
"guid_records", "B", "C", "K", "L1", "L2", "T", "c9_records" };
if (expected.TryGetProperty("sum_L2", out var sum))
{
Assert.True(sum.GetInt64() == doc.L2.Sum(v => (long)v), $"{name}: sum_L2");
Assert.True(sum.GetInt64() == l2.Sum(v => (long)v), $"{name}: sum_L2");
handled.Add("sum_L2");
}
if (expected.TryGetProperty("T1_minus_B_div_32", out var blocks))
{
Assert.True(blocks.GetInt64() == (doc.T[1] - (long)doc.B) / 32, $"{name}: T1_minus_B_div_32");
Assert.True(blocks.GetInt64() == (t[1] - (long)doc.BaseOffset) / 32, $"{name}: T1_minus_B_div_32");
handled.Add("T1_minus_B_div_32");
}
if (expected.TryGetProperty("sections", out var sections))
Expand Down
Loading