diff --git a/CHANGELOG.md b/CHANGELOG.md index df23bf9..7ea4a5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,16 @@ API between minor releases. name, and the parts without a usable geometry; `TdbSceneResult.PartCount` counts the parts. The IFC, scene JSON and 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. +- `DbvDocument.DomainId`, `Generation`, `BaseOffset`, `CurrentOffset` and `LastEventOffset`: names for `Prologue[1]`, + `ListHeader[3]` and the byte offsets of the domain events. + +### Breaking + +- `DbvDocument` no longer has the raw properties `B`, `C`, `L1`, `L2` and `T` of 0.1.0. Use `BaseOffset` for `B`, + `CurrentOffset` for `T[1]`, `LastEventOffset` for `T[4]`, `ListHeader[3]` for `T[0]` (the reader rejects a file where + they differ) and `C9Records.Count` for `T[5]`. `C`, `L1`, `L2`, `T[2]` and `T[3]` have no property; their bytes stay + in `Payload`, at the offsets `docs/public-api.md` gives. The reader warns when `C` is not 5 or when `T[2]` or `T[3]` + is not 0; it does not check `L1` and `L2`. ### Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1a081a7..846f1f0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -106,8 +106,11 @@ that breaks a consumer fails the pack. Record an intended removal in exceptions, and values that are kept despite a mismatch as warnings. - Treat every file as untrusted input: bound every read and size, and report malformed data with `InvalidDataException` and its offset. -- Describe only what the code does. A field whose meaning is not known is - exposed as a raw value and documented as such. +- Describe only what the code does. A public property for a value whose meaning + is not known is named by its byte offset, as `Db1Document.IdMapField65`, and + documented as raw. A value whose role the files confirm gets a role name. A + value without a property of its own stays in the raw bytes that the type + gives, as `DbvDocument.Payload`. ## Validating output diff --git a/docs/public-api.md b/docs/public-api.md index 552da97..6857a75 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -82,10 +82,17 @@ 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), `Prologue`, `ListHeader`, `GuidRecords`, `C9Records`, `Sections` and `Payload`. Some of the numbers have no property; see below. | | `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`. | +After the GUID records of a DBV@ file come little-endian 32-bit words, from offset +`52 + Name.Length + 24 * GuidRecords.Count` of `Payload`: `B`, `C`, the length `K`, the `K` words of `L1`, the `K` +signed words of `L2` and the six words `T[0]` to `T[5]`. Warnings and errors name them like this. `BaseOffset` is `B`, +`CurrentOffset` is `T[1]` and `LastEventOffset` is `T[4]`. The reader warns when `C` is not 5, `T[1]` is not +`B + 32 * K`, `T[2]` or `T[3]` is not 0, or `T[4]` is not `T[1] - 32`. It rejects a file where `T[0]` differs from +`ListHeader[3]`. `T[5]` is the number of C9 records. `L1` and `L2` are not checked. + The walk of a model database starts at its first table section and must end exactly at the end of `Payload`; a section without a key after one with a key, a gap or bytes after the last section is an error. The bytes before the first section, other than the header and the id map, are not interpreted; read them from `Payload`. diff --git a/src/TdbIO/CompatibilitySuppressions.xml b/src/TdbIO/CompatibilitySuppressions.xml new file mode 100644 index 0000000..c611aad --- /dev/null +++ b/src/TdbIO/CompatibilitySuppressions.xml @@ -0,0 +1,76 @@ + + + + + + CP0002 + M:TdbIO.DbvDocument.get_B + lib/net10.0/TdbIO.dll + lib/net10.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_C + lib/net10.0/TdbIO.dll + lib/net10.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_L1 + lib/net10.0/TdbIO.dll + lib/net10.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_L2 + lib/net10.0/TdbIO.dll + lib/net10.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_T + lib/net10.0/TdbIO.dll + lib/net10.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_B + lib/net8.0/TdbIO.dll + lib/net8.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_C + lib/net8.0/TdbIO.dll + lib/net8.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_L1 + lib/net8.0/TdbIO.dll + lib/net8.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_L2 + lib/net8.0/TdbIO.dll + lib/net8.0/TdbIO.dll + true + + + CP0002 + M:TdbIO.DbvDocument.get_T + lib/net8.0/TdbIO.dll + lib/net8.0/TdbIO.dll + true + + \ No newline at end of file diff --git a/src/TdbIO/DbvDocument.cs b/src/TdbIO/DbvDocument.cs index b3b7f80..9ca72ae 100644 --- a/src/TdbIO/DbvDocument.cs +++ b/src/TdbIO/DbvDocument.cs @@ -4,12 +4,13 @@ namespace TdbIO; /// A gzip file whose content starts with DBV@: 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 . +/// sections. Some of the numbers have no property and stay in . The reader checks only part of the +/// numbers; where one of those differs from what is always seen, it is reported in +/// or the file is rejected. public sealed class DbvDocument : TdbDocument { internal DbvDocument(IReadOnlyList warnings, string name, IReadOnlyList prologue, IReadOnlyList listHeader, - IReadOnlyList guidRecords, uint b, uint c, IReadOnlyList l1, IReadOnlyList l2, IReadOnlyList t, + IReadOnlyList guidRecords, uint baseOffset, uint currentOffset, uint lastEventOffset, IReadOnlyList c9Records, IReadOnlyList sections, ReadOnlyMemory payload) : base(TdbFileKind.Dbv, warnings) { @@ -17,11 +18,9 @@ internal DbvDocument(IReadOnlyList warnings, string name, IReadOnlyList< 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; @@ -36,17 +35,17 @@ internal DbvDocument(IReadOnlyList warnings, string name, IReadOnlyList< /// 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 base byte offset of the domain events, as stored after the GUID records. The reader does not check + /// it on its own; it is part of the check of . + public uint BaseOffset { get; } - /// The domain event level (alias for ; expected to be 5). - public uint EventLevel => C; + /// The byte offset after the domain events. The reader warns when it is not BaseOffset + 32 · K, + /// where K is the length stored before the lists. + public uint CurrentOffset { get; } - /// 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 byte offset of the last domain event. The reader warns when it is not + /// CurrentOffset - 32. + public uint LastEventOffset { get; } /// The six raw numbers after the name. public IReadOnlyList Prologue { get; } @@ -57,22 +56,6 @@ internal DbvDocument(IReadOnlyList warnings, string name, IReadOnlyList< /// The GUID records in file order. public IReadOnlyList GuidRecords { get; } - /// The raw number after the GUID records. - public uint B { get; } - - /// The raw number after . - public uint C { get; } - - /// The first list of raw numbers; its length is stored before it. - public IReadOnlyList L1 { get; } - - /// The second list of raw numbers, signed, as long as . - public IReadOnlyList L2 { get; } - - /// The six raw numbers after the lists. The first one equals the last number of ; - /// the last one is the number of . - public IReadOnlyList T { get; } - /// The records that start with C9 C0 CE DB. public IReadOnlyList C9Records { get; } diff --git a/src/TdbIO/Internal/DbvReader.cs b/src/TdbIO/Internal/DbvReader.cs index f9f9514..b289138 100644 --- a/src/TdbIO/Internal/DbvReader.cs +++ b/src/TdbIO/Internal/DbvReader.cs @@ -68,11 +68,8 @@ public static DbvDocument Read(byte[] payload, List warnings, Encoding? Expect(warnings, c == 5, "word C", p + 4); long listLength = k32; Bytes.Need(p, 12 + 8 * listLength + 24, length, "DBV@ lists"); - p += 12; - var l1 = ReadU32s(d, p, (int)listLength); - p += 4 * listLength; - var l2 = new int[listLength]; - for (int i = 0; i < l2.Length; i++, p += 4) l2[i] = Bytes.I32(d, p); + // L1 and L2 are skipped: the reader does not use or check them, and the payload keeps their bytes. + p += 12 + 8 * listLength; var t = ReadU32s(d, p, 6); if (t[0] != listHeader[3]) @@ -95,8 +92,7 @@ public static DbvDocument Read(byte[] payload, List 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 d, long at, int count) diff --git a/src/TdbIO/TdbIO.csproj b/src/TdbIO/TdbIO.csproj index b0e4cff..f1732f1 100644 --- a/src/TdbIO/TdbIO.csproj +++ b/src/TdbIO/TdbIO.csproj @@ -7,9 +7,11 @@ TdbIO TdbIO true - + true 0.1.0 + $(MSBuildProjectDirectory)\CompatibilitySuppressions.xml