From fdc07abc6c918d5bb5a9ed132052d7a67ce1dabd Mon Sep 17 00:00:00 2001 From: mahach666 <79989386+mahach666@users.noreply.github.com> Date: Sat, 28 Nov 2026 17:27:07 +0300 Subject: [PATCH 1/2] Read the drawings of a model database from table 27 The drawing table (key 27, rows of 256 bytes) holds one row per drawing of the model: its id, mark, save times, the name of its .dg file next to the model database and the drawing type name. The layout is verified black-box on all sample containers and recorded in the format notes of the project (sections 1.11 and 2.10 of the private format spec). - DrawingRow: the typed decoder of the row body, with the mark, the file name and the type name as text values in the encoding rule of the rows; the words of unknown meaning stay in the raw body. - TableRow.AsDrawing(), TableSection.AsDrawings() and Db1Document.ReadDrawings() read the table on request; a file with no table-section area (text sections only) has no drawings. - tdbio info prints the number of drawings as drawings, in text and JSON. Fixes none; feature from the format research. --- CHANGELOG.md | 3 ++ docs/cli.md | 2 +- docs/public-api.md | 4 +- src/TdbIO.Cli/Cli.cs | 8 ++++ src/TdbIO/Db1Document.Tables.cs | 24 +++++++++++ src/TdbIO/ModelRows.cs | 52 +++++++++++++++++++++++ src/TdbIO/TableRow.cs | 3 ++ src/TdbIO/TableSection.cs | 3 ++ tests/TdbIO.Tests/CliTests.cs | 36 ++++++++++++++++ tests/TdbIO.Tests/TableRowDecoderTests.cs | 50 ++++++++++++++++++++++ 10 files changed, 183 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ea4a5e..4bdb1a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ API between minor releases. - A standalone HTML viewer of the scene: `tdbio export model.db1 viewer.html`. - `TableRow.TextEncoding` and `Decode(ReadOnlySpan, Encoding)` on the decoded row types with text: the text values of table rows can be read in a given encoding. `TdbReadOptions.TextEncoding` now applies to them too. +- `DrawingRow`, the typed decoder of the drawing table (table 27, size 256): `Db1Document.ReadDrawings()` and the + `AsDrawings()` bulk decoder give the mark, file name, type name and the save times of every drawing of a model + database. `tdbio info` prints their number as `drawings`. - Tests of the adapter in `TdbIO.Scene.Tests`, and test runs on Linux and macOS in CI. - `docs/versions.md`: differences between Tekla Structures versions. - Geometry diagnostics of the scene adapter: `TdbSceneResult.GeometryDiagnostics` (`TdbGeometryDiagnostic`) reports diff --git a/docs/cli.md b/docs/cli.md index 8931888..662a731 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -76,7 +76,7 @@ JSON. | Kind | Keys | | --- | --- | -| `Db1` | `version`, `modelGuid`, `idMapEntries`, `idMapField65` (hex in text), `idMapField73`, `textSections`, `textChains`, `saveStamps`, `lastSavedAt` (the latest save stamp date) | +| `Db1` | `version`, `modelGuid`, `idMapEntries`, `idMapField65` (hex in text), `idMapField73`, `drawings` (the number of rows in the drawing table), `textSections`, `textChains`, `saveStamps`, `lastSavedAt` (the latest save stamp date) | | `Db2` | `version`, `modelGuid`, `records`, `rows` (the sum of the row counts) | | `GuidMapper` | `pairs` | | `IdRanges` | `next`, `ranges` | diff --git a/docs/public-api.md b/docs/public-api.md index 6857a75..51e1129 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -69,7 +69,8 @@ offset or line number. A warning never contains text from the file. Warnings are | Type | Use | | --- | --- | -| `Db1Document` | A model database (`.db1`, `xslib.db1` and their `.bak` copies). `Version` (`d.dd`), `ModelGuid`, `IdMap` (entries in file order, or null), `IdMapField65` and `IdMapField73` (raw numbers, null when the id map is not read), `Payload` (the whole unpacked file; offsets refer to it). `ReadTextSections()` and `ReadTables()` read on request and build new lists on each call. `ReadModel()` decodes a connected, read-only object model graph () of parts, assemblies, bolts, welds and attributes. | +| `Db1Document` | A model database (`.db1`, `xslib.db1` and their `.bak` copies). `Version` (`d.dd`), `ModelGuid`, `IdMap` (entries in file order, or null), `IdMapField65` and `IdMapField73` (raw numbers, null when the id map is not read), `Payload` (the whole unpacked file; offsets refer to it). `ReadTextSections()` and `ReadTables()` read on request and build new lists on each call. `ReadDrawings()` reads the drawing table (table 27) on request. + `ReadModel()` decodes a connected, read-only object model graph () of parts, assemblies, bolts, welds and attributes. | | `IdMapEntry` | `Sequence`, `Id` (GUID) and `Value` (raw, meaning not known). | | `TextSection` | A section of 54-byte text rows: `Offset`, `RowCount`, `Chains` (in the file order of their heads) and `OrphanRowIds` (rows that belong to no chain, reported instead of dropped). The links of all rows are checked, orphans included: a link to a missing id, a cycle or two rows linking to one row is an error. | | `TextChain` | One text: `HeadId`, `HeadTag` and `HeadField13` (raw), `RowIds` (chain order), `Text` (the bytes as stored, not decoded). `IsSaveStamp` is true when the text starts with `Save:`; `SavedAt` is its date and time, or null. `RevealSaveText()` returns the revealed bytes of a save stamp: fields separated by `;`. Fields after the date and time can hold names of people or machines; do not log them. | @@ -106,6 +107,7 @@ Typed record structs decoded from the row bodies of the most common model databa | `ObjectRow` | 1 | 72 | `Id`, `ParentId` (`kuuluu`), `AssemblyId`, `Guid` (128-bit RFC 4122), `Type`, `Subtype`, `ExternalType`, `Mask1`, `Mask2`, `ObjFlag`, `OwnerId`, `PrivilegeId`. | | `AssemblyRow` | 2 | 92 | `Id`, `Type`, `Class`, `MainPartId` (`dum`), `Lot`, `Name`, `Flags`, `MainPartByUser`. | | `CoordsysRow` | 3 | 40 | `Id`, `AttrId`, origin coordinates `X`, `Y`, `Z`, `Length`. | +| `DrawingRow` | 27 | 256 | One drawing of the model database: `Id`, `ObjType` (34 in the samples), `Mark`, `CreatedAt` and `ModifiedAt` (Unix seconds), `FileName` (the `.dg` file next to the model database) and `TypeName`. | | `PartRow` | 10 | 64 | `Id`, `PartAttrId`, `PositioningAttrId`, `StartPointId` (`p1`), `EndPointId` (`p2`), `GeometryTreeRootId`, `CoordsysAttrId`, `Reserved`, local coordinate system `CoordsysX`, `CoordsysY`, `CoordsysZ`, `Length`. | | `PointRow` | 13 | 32 | `Id`, `Visibility`, 3D coordinates `X`, `Y`, `Z` in millimeters. | | `RelationRow` | 16 | 60 | `Id`, `Type`, `Id1`, `Id2`, `Guid` (string), `Flags`. | diff --git a/src/TdbIO.Cli/Cli.cs b/src/TdbIO.Cli/Cli.cs index 76bce10..6fcb2d6 100644 --- a/src/TdbIO.Cli/Cli.cs +++ b/src/TdbIO.Cli/Cli.cs @@ -247,6 +247,14 @@ private static Command Parse(string[] args) Add("idMapField65", db1.IdMapField65 is uint field65 ? new Hex(field65) : null); Add("idMapField73", db1.IdMapField73); try + { + Add("drawings", db1.ReadDrawings().Count); + } + catch (InvalidDataException e) + { + error ??= e.Message; + } + try { var sections = db1.ReadTextSections(); var chains = sections.SelectMany(s => s.Chains).ToList(); diff --git a/src/TdbIO/Db1Document.Tables.cs b/src/TdbIO/Db1Document.Tables.cs index 62fe163..944bf00 100644 --- a/src/TdbIO/Db1Document.Tables.cs +++ b/src/TdbIO/Db1Document.Tables.cs @@ -16,4 +16,28 @@ public IReadOnlyList ReadTables() => /// Decodes the table sections into a connected, read-only object model of parts, assemblies, bolts, welds and attributes. /// A new representing the decoded model object graph. public TeklaModel ReadModel() => ModelBuilder.Build(this); + + /// Reads the drawing table (the section with key 27 and rows of 256 bytes) and decodes its rows. Builds a + /// new list on each call. + /// The drawings in file order; an empty list when the file has no drawing table. A file can hold text + /// sections only, with no table-section area after the id map at all; that is an empty list too. + /// The table-section area exists but a section in it is malformed, as + /// . + public IReadOnlyList ReadDrawings() + { + int first; + try + { + first = SectionWalker.FindFirstSection(Payload.Span); + } + catch (InvalidDataException) + { + // No table-section area: the payload ends after the id map or holds text sections only. + return Array.Empty(); + } + + var section = SectionWalker.Walk(Payload, first, 0, SectionMode.Db1, null, _textEncoding) + .FirstOrDefault(s => s.Key == DrawingRow.TableKey && s.RowSize == DrawingRow.ExpectedRowSize); + return section?.AsDrawings() ?? Array.Empty(); + } } diff --git a/src/TdbIO/ModelRows.cs b/src/TdbIO/ModelRows.cs index 0beae2a..13d92e9 100644 --- a/src/TdbIO/ModelRows.cs +++ b/src/TdbIO/ModelRows.cs @@ -310,6 +310,58 @@ public static WeldingRow Decode(ReadOnlySpan body) public static WeldingRow Decode(TableRow row) => Decode(row.Body.Span); } +/// Decoded row of table 27 (size 256): one drawing of the model database, with its mark, file name, type name +/// and save times. The words the meaning of which is not known stay in the raw body (). +/// The drawing identifier; the object of type 34 in table 1 with the same identifier. +/// The object type code of the drawing; 34 in the samples. +/// The mark of the drawing (for example "G [6]", "C [W.20 - 1]"). +/// The creation time of the drawing, as Unix seconds. +/// The last modification time of the drawing, as Unix seconds, or 0 when there is none. +/// The file name of the drawing next to the model database (for example "D304d0d41-fe43-….dg"). +/// The type name of the drawing (for example "GA-drawing", "CAST UNIT - FRAME 4xA3", "BEAM"). +public readonly record struct DrawingRow( + int Id, + int ObjType, + string Mark, + uint CreatedAt, + uint ModifiedAt, + string FileName, + string TypeName) +{ + /// The expected row body size in bytes: 256. + public const int ExpectedRowSize = 256; + + /// The table key in model database sections: 27. + public const int TableKey = 27; + + /// Decodes a row body into a , choosing the encoding of its text values from their bytes. + public static DrawingRow Decode(ReadOnlySpan body) => Decode(body, null); + + /// Decodes a row body into a , reading its text values in . + /// The row body. + /// The encoding of the text values, or null to choose it from the bytes of each value: + /// ASCII, UTF-8, then code page 1251 or 1252. + public static DrawingRow Decode(ReadOnlySpan body, Encoding? textEncoding) => Decode(body, textEncoding, null); + + // codePage: the code page chosen for the whole file for the values that are neither ASCII nor UTF-8 (RowText). + internal static DrawingRow Decode(ReadOnlySpan body, Encoding? textEncoding, int? codePage) + { + if (body.Length < ExpectedRowSize) + throw new ArgumentException($"Row body length {body.Length} is smaller than expected size {ExpectedRowSize}.", nameof(body)); + return new( + Bytes.I32(body, 0), + Bytes.I32(body, 4), + Bytes.Text(body, 8, 64, textEncoding, codePage), + Bytes.U32(body, 88), + Bytes.U32(body, 92), + Bytes.Text(body, 100, 44, textEncoding, codePage), + Bytes.Text(body, 144, 84, textEncoding, codePage)); + } + + /// Decodes the body of into a . + public static DrawingRow Decode(TableRow row) => Decode(row.Body.Span, row.Text?.Encoding, row.Text?.CodePage); +} + /// Decoded row of table 38 (numattr, size 24): numeric attribute association. /// The numeric attribute row identifier (primary key). /// Identifier of the attribute value in table 48 (numattr_attr). diff --git a/src/TdbIO/TableRow.cs b/src/TdbIO/TableRow.cs index 1ecfed8..5334cc5 100644 --- a/src/TdbIO/TableRow.cs +++ b/src/TdbIO/TableRow.cs @@ -68,6 +68,9 @@ public bool Equals(TableRow other) => /// Decodes the row body as a (table 20, size 24). public WeldingRow AsWelding() => WeldingRow.Decode(this); + /// Decodes the row body as a (table 27, size 256). + public DrawingRow AsDrawing() => DrawingRow.Decode(this); + /// Decodes the row body as a (table 38, size 24). public NumAttrRow AsNumAttr() => NumAttrRow.Decode(this); diff --git a/src/TdbIO/TableSection.cs b/src/TdbIO/TableSection.cs index 61e4107..af5b339 100644 --- a/src/TdbIO/TableSection.cs +++ b/src/TdbIO/TableSection.cs @@ -82,6 +82,9 @@ private IReadOnlyList DecodeRows(int expectedSize, Func decod /// Decodes all rows of this section as (size 24). public IReadOnlyList AsWeldings() => DecodeRows(WeldingRow.ExpectedRowSize, r => r.AsWelding()); + /// Decodes all rows of this section as (size 256). + public IReadOnlyList AsDrawings() => DecodeRows(DrawingRow.ExpectedRowSize, r => r.AsDrawing()); + /// Decodes all rows of this section as (size 24). public IReadOnlyList AsNumAttrs() => DecodeRows(NumAttrRow.ExpectedRowSize, r => r.AsNumAttr()); diff --git a/tests/TdbIO.Tests/CliTests.cs b/tests/TdbIO.Tests/CliTests.cs index 98a7e4f..ca9cc4e 100644 --- a/tests/TdbIO.Tests/CliTests.cs +++ b/tests/TdbIO.Tests/CliTests.cs @@ -226,6 +226,42 @@ public void InfoJsonParsesAndHoldsWarnings() Assert.DoesNotContain("m.db1", stdout); } + // drawings + + private static byte[] DrawingRowBody() + { + var body = new byte[DrawingRow.ExpectedRowSize]; + BinaryPrimitives.WriteInt32LittleEndian(body.AsSpan(0), 1001); + BinaryPrimitives.WriteInt32LittleEndian(body.AsSpan(4), 34); + Encoding.ASCII.GetBytes("G [1]").CopyTo(body.AsSpan(8)); + BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(88), 1708336801); + Encoding.ASCII.GetBytes("D00000000-0000-0000-0000-000000000000.dg").CopyTo(body.AsSpan(100)); + Encoding.ASCII.GetBytes("GA-drawing").CopyTo(body.AsSpan(144)); + return body; + } + + private string Db1WithDrawings() => File("d.db1", Gzip(Db1TablesPayload( + Db1Section(null, 4, [1], (0x04, Counting(4), 1, 2)), + Db1Section(27, 256, [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], (0x04, DrawingRowBody(), 1, 2))))); + + [Fact] + public void InfoCountsTheDrawingsOfTheDrawingTable() + { + var (exit, stdout, stderr) = Run("info", Db1WithDrawings()); + Assert.Equal(Cli.ExitOk, exit); + Assert.Empty(stderr); + Assert.Equal("1", Fields(stdout)["drawings"]); + + var (jsonExit, jsonOut, _) = Run("info", Db1WithDrawings(), "--json"); + Assert.Equal(Cli.ExitOk, jsonExit); + using var json = JsonDocument.Parse(jsonOut); + Assert.Equal(1, json.RootElement.GetProperty("drawings").GetInt32()); + + // A file without the drawing table reports none. + var (_, without, _) = Run("info", Db1WithTables()); + Assert.Equal("0", Fields(without)["drawings"]); + } + // tables [Fact] diff --git a/tests/TdbIO.Tests/TableRowDecoderTests.cs b/tests/TdbIO.Tests/TableRowDecoderTests.cs index 2fe11a2..307525d 100644 --- a/tests/TdbIO.Tests/TableRowDecoderTests.cs +++ b/tests/TdbIO.Tests/TableRowDecoderTests.cs @@ -110,6 +110,56 @@ public void AssemblyRowTextWithAnUndefinedByteIsAnErrorAtItsOffset() Assert.Equal(21, e.Offset); Assert.Contains("cp1251", e.Message); } + [Fact] + public void DrawingRowDecodesMarkFileNameTypeAndTimes() + { + // The layout of the drawing table (table 27, size 256) is section 1.11 of the format notes of the project. + var row = MakeRow(DrawingRow.ExpectedRowSize, span => + { + BinaryPrimitives.WriteInt32LittleEndian(span[0..], 97358816); + BinaryPrimitives.WriteInt32LittleEndian(span[4..], 34); + Encoding.ASCII.GetBytes("G [6]").CopyTo(span[8..]); + BinaryPrimitives.WriteUInt32LittleEndian(span[88..], 1708336801); + BinaryPrimitives.WriteUInt32LittleEndian(span[92..], 1711022910); + Encoding.ASCII.GetBytes("D83a6d6c9-dd0c-4bbd-b977-553b6cf3701c.dg").CopyTo(span[100..]); + Encoding.ASCII.GetBytes("GA-drawing").CopyTo(span[144..]); + }); + + var drawing = row.AsDrawing(); + Assert.Equal(97358816, drawing.Id); + Assert.Equal(34, drawing.ObjType); + Assert.Equal("G [6]", drawing.Mark); + Assert.Equal(1708336801u, drawing.CreatedAt); + Assert.Equal(1711022910u, drawing.ModifiedAt); + Assert.Equal("D83a6d6c9-dd0c-4bbd-b977-553b6cf3701c.dg", drawing.FileName); + Assert.Equal("GA-drawing", DrawingRow.Decode(row.Body.Span).TypeName); + } + + [Fact] + public void DrawingRowDecodesTheSingleByteTextOfTheSavingSystem() + { + var row = MakeRow(DrawingRow.ExpectedRowSize, span => + { + CodePagesEncodingProvider.Instance.GetEncoding(1251)!.GetBytes("План").CopyTo(span[8..]); + }); + + Assert.Equal("План", row.AsDrawing().Mark); + } + + [Fact] + public void DrawingRowTextWithAnUndefinedByteIsAnErrorAtItsOffset() + { + // One high byte of the upper half of two chooses code page 1251, which does not define 0x98. + var row = MakeRow(DrawingRow.ExpectedRowSize, span => + { + span[8] = 0xC0; + span[9] = 0x98; + }); + + var e = Assert.Throws(() => row.AsDrawing()); + Assert.Equal(9, e.Offset); + Assert.Contains("cp1251", e.Message); + } [Fact] public void CoordsysRowDecodesCorrectly() From 1474312332417493c1e24ee0e7e74489b26ec6f1 Mon Sep 17 00:00:00 2001 From: mahach666 <79989386+mahach666@users.noreply.github.com> Date: Sat, 28 Nov 2026 23:49:40 +0300 Subject: [PATCH 2/2] Count only live drawings and report drawing tables that cannot be read ReadDrawings() leaves out the deleted and superseded rows, and the text of table 27 counts toward the code page chosen once for the file. Only a payload whose section separators all open text sections has no table area. Otherwise tables that cannot be read are an error instead of an empty list, and so is a drawing table with rows of another size. tdbio info warns and leaves drawings out when it cannot count them, so its exit code stays what it was before it counted drawings. Use made-up values in the tests and drop the XML doc examples and the reference to notes outside the repository. Join the split Db1Document row of the API table. --- CHANGELOG.md | 7 ++- docs/cli.md | 7 ++- docs/public-api.md | 5 +- src/TdbIO.Cli/Cli.cs | 17 ++--- src/TdbIO/Db1Document.Tables.cs | 34 +++++----- src/TdbIO/Internal/RowText.cs | 1 + src/TdbIO/Internal/SectionWalker.cs | 20 ++++++ src/TdbIO/Internal/TextSectionReader.cs | 3 + src/TdbIO/ModelRows.cs | 6 +- tests/TdbIO.Tests/CliTests.cs | 52 ++++++++++++++-- tests/TdbIO.Tests/RowTextTests.cs | 19 ++++++ tests/TdbIO.Tests/SectionWalkerTests.cs | 75 +++++++++++++++++++++++ tests/TdbIO.Tests/TableRowDecoderTests.cs | 26 ++++---- 13 files changed, 218 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bdb1a8..74986e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,9 +22,10 @@ API between minor releases. - A standalone HTML viewer of the scene: `tdbio export model.db1 viewer.html`. - `TableRow.TextEncoding` and `Decode(ReadOnlySpan, Encoding)` on the decoded row types with text: the text values of table rows can be read in a given encoding. `TdbReadOptions.TextEncoding` now applies to them too. -- `DrawingRow`, the typed decoder of the drawing table (table 27, size 256): `Db1Document.ReadDrawings()` and the - `AsDrawings()` bulk decoder give the mark, file name, type name and the save times of every drawing of a model - database. `tdbio info` prints their number as `drawings`. +- `DrawingRow`, the typed decoder of the drawing table (table 27, size 256), with the mark, file name, type name and + the save times of a drawing. `Db1Document.ReadDrawings()` gives the drawings of a model database without the deleted + and superseded rows, and the `AsDrawings()` bulk decoder decodes every row of a section. `tdbio info` prints the + number of drawings as `drawings`, or warns why it cannot count them. - Tests of the adapter in `TdbIO.Scene.Tests`, and test runs on Linux and macOS in CI. - `docs/versions.md`: differences between Tekla Structures versions. - Geometry diagnostics of the scene adapter: `TdbSceneResult.GeometryDiagnostics` (`TdbGeometryDiagnostic`) reports diff --git a/docs/cli.md b/docs/cli.md index 662a731..6045584 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -34,7 +34,7 @@ from its extension (reports, which have no signature, are recognised by the `.xs | Option | Commands | Effect | | --- | --- | --- | | `--json` | all | Write one indented JSON object (UTF-8) instead of text. | -| `--encoding ` | `info`, `export` | Read a template or report, or the text values of the table rows of a model database (`.db1`) or DBV@ file, with this encoding instead of detecting it: `ascii`, `utf-8`, `cp1251` or `cp1252`. Give it for a model saved with a Western European code page, which the detection reads as `cp1251`. The encoding is strict: a byte it does not define is an input error. Given for any other kind of file, it is a usage error. | +| `--encoding ` | `info`, `export` | Read a template or report, or the text values of the table rows of a model database (`.db1`) or DBV@ file, with this encoding instead of detecting it: `ascii`, `utf-8`, `cp1251` or `cp1252`. Give it for a model saved with a Western European code page, which the detection reads as `cp1251`. The encoding is strict: a byte it does not define is an input error, except in the text of a drawing under `info`, which then warns instead of counting the drawings. Given for any other kind of file, it is a usage error. | An option given twice is a usage error. @@ -76,7 +76,7 @@ JSON. | Kind | Keys | | --- | --- | -| `Db1` | `version`, `modelGuid`, `idMapEntries`, `idMapField65` (hex in text), `idMapField73`, `drawings` (the number of rows in the drawing table), `textSections`, `textChains`, `saveStamps`, `lastSavedAt` (the latest save stamp date) | +| `Db1` | `version`, `modelGuid`, `idMapEntries`, `idMapField65` (hex in text), `idMapField73`, `drawings` (the rows of the drawing table that are not deleted or superseded), `textSections`, `textChains`, `saveStamps`, `lastSavedAt` (the latest save stamp date) | | `Db2` | `version`, `modelGuid`, `records`, `rows` (the sum of the row counts) | | `GuidMapper` | `pairs` | | `IdRanges` | `next`, `ranges` | @@ -87,6 +87,9 @@ JSON. | `Report` | `encoding`, `lines`, `pages` (the number of form feeds), `endsWithLineBreak` | For a model database `info` also reads the text sections, so a malformed text section makes it fail with exit code 2. +It reads the table sections to count the drawings. When it cannot (the tables cannot be read, the drawing table has rows +of another size, or a text value of a drawing does not decode), it leaves `drawings` out and adds a warning that says +why; like other warnings, it does not change the exit code. Example, on a synthetic DSTV NC file: diff --git a/docs/public-api.md b/docs/public-api.md index 51e1129..9f8ffb0 100644 --- a/docs/public-api.md +++ b/docs/public-api.md @@ -69,8 +69,7 @@ offset or line number. A warning never contains text from the file. Warnings are | Type | Use | | --- | --- | -| `Db1Document` | A model database (`.db1`, `xslib.db1` and their `.bak` copies). `Version` (`d.dd`), `ModelGuid`, `IdMap` (entries in file order, or null), `IdMapField65` and `IdMapField73` (raw numbers, null when the id map is not read), `Payload` (the whole unpacked file; offsets refer to it). `ReadTextSections()` and `ReadTables()` read on request and build new lists on each call. `ReadDrawings()` reads the drawing table (table 27) on request. - `ReadModel()` decodes a connected, read-only object model graph () of parts, assemblies, bolts, welds and attributes. | +| `Db1Document` | A model database (`.db1`, `xslib.db1` and their `.bak` copies). `Version` (`d.dd`), `ModelGuid`, `IdMap` (entries in file order, or null), `IdMapField65` and `IdMapField73` (raw numbers, null when the id map is not read), `Payload` (the whole unpacked file; offsets refer to it). `ReadTextSections()` and `ReadTables()` read on request and build new lists on each call. `ReadDrawings()` reads the drawing table (table 27) on request, without its deleted and superseded rows. `ReadModel()` decodes a connected, read-only object model graph () of parts, assemblies, bolts, welds and attributes. | | `IdMapEntry` | `Sequence`, `Id` (GUID) and `Value` (raw, meaning not known). | | `TextSection` | A section of 54-byte text rows: `Offset`, `RowCount`, `Chains` (in the file order of their heads) and `OrphanRowIds` (rows that belong to no chain, reported instead of dropped). The links of all rows are checked, orphans included: a link to a missing id, a cycle or two rows linking to one row is an error. | | `TextChain` | One text: `HeadId`, `HeadTag` and `HeadField13` (raw), `RowIds` (chain order), `Text` (the bytes as stored, not decoded). `IsSaveStamp` is true when the text starts with `Save:`; `SavedAt` is its date and time, or null. `RevealSaveText()` returns the revealed bytes of a save stamp: fields separated by `;`. Fields after the date and time can hold names of people or machines; do not log them. | @@ -107,11 +106,11 @@ Typed record structs decoded from the row bodies of the most common model databa | `ObjectRow` | 1 | 72 | `Id`, `ParentId` (`kuuluu`), `AssemblyId`, `Guid` (128-bit RFC 4122), `Type`, `Subtype`, `ExternalType`, `Mask1`, `Mask2`, `ObjFlag`, `OwnerId`, `PrivilegeId`. | | `AssemblyRow` | 2 | 92 | `Id`, `Type`, `Class`, `MainPartId` (`dum`), `Lot`, `Name`, `Flags`, `MainPartByUser`. | | `CoordsysRow` | 3 | 40 | `Id`, `AttrId`, origin coordinates `X`, `Y`, `Z`, `Length`. | -| `DrawingRow` | 27 | 256 | One drawing of the model database: `Id`, `ObjType` (34 in the samples), `Mark`, `CreatedAt` and `ModifiedAt` (Unix seconds), `FileName` (the `.dg` file next to the model database) and `TypeName`. | | `PartRow` | 10 | 64 | `Id`, `PartAttrId`, `PositioningAttrId`, `StartPointId` (`p1`), `EndPointId` (`p2`), `GeometryTreeRootId`, `CoordsysAttrId`, `Reserved`, local coordinate system `CoordsysX`, `CoordsysY`, `CoordsysZ`, `Length`. | | `PointRow` | 13 | 32 | `Id`, `Visibility`, 3D coordinates `X`, `Y`, `Z` in millimeters. | | `RelationRow` | 16 | 60 | `Id`, `Type`, `Id1`, `Id2`, `Guid` (string), `Flags`. | | `WeldingRow` | 20 | 24 | `Id`, `CommonAttrId`, `Seam1Id`, `Seam2Id`, `CompoundSeam1Id`, `CompoundSeam2Id`. | +| `DrawingRow` | 27 | 256 | One drawing of the model database: `Id`, `ObjType` (34 in the samples), `Mark`, `CreatedAt` and `ModifiedAt` (Unix seconds), `FileName` (the `.dg` file next to the model database) and `TypeName`. | | `NumAttrRow` | 38 | 24 | `Id`, `AttrId`, `FatherId`, `OwnerId`, `Flags`, `NameId`. | | `StrAttrRow` | 39 | 24 | `Id`, `AttrId`, `FatherId`, `OwnerId`, `Flags`, `NameId`. | | `PartAttrRow` | 44 | 372 | `Id`, `ObjType`, `FormType`, `ObjClass`, `AssStartNo`, `Flags`, `NPoints`, `PartFlags`, `Prefix`, `Name`, `Profile`, `ParameterStringId`, `AssemblyPosition`, `AssemblyName`, `Material`, `Finish`, `AssemblyType`, `PourPhase`. | diff --git a/src/TdbIO.Cli/Cli.cs b/src/TdbIO.Cli/Cli.cs index 6fcb2d6..a8c7148 100644 --- a/src/TdbIO.Cli/Cli.cs +++ b/src/TdbIO.Cli/Cli.cs @@ -97,17 +97,17 @@ internal static int Run(string[] args, TextWriter stdout, TextWriter stderr) // Everything is read before anything is written, so an error never leaves half an output. var output = new StringWriter(); string? error = null; - var exportWarnings = new List(); + var commandWarnings = new List(); switch (command.Name) { - case "info": error = Info(output, doc, command.Json); break; + case "info": error = Info(output, doc, command.Json, commandWarnings); break; case "tables": Tables(output, doc, command.Json); break; - case "export": exportWarnings.AddRange(Export(output, doc, command)); break; + case "export": commandWarnings.AddRange(Export(output, doc, command)); break; default: Text(output, doc, command.Json); break; } stdout.Write(output.ToString()); foreach (string warning in doc.Warnings) stderr.WriteLine($"tdbio: warning: {warning}"); - foreach (string warning in exportWarnings) stderr.WriteLine($"tdbio: warning: {warning}"); + foreach (string warning in commandWarnings) stderr.WriteLine($"tdbio: warning: {warning}"); if (error != null) { stderr.WriteLine($"tdbio: {error}"); @@ -231,7 +231,7 @@ private static Command Parse(string[] args) _ => throw new UsageException($"Unknown encoding '{name}'."), }; - private static string? Info(TextWriter w, TdbDocument doc, bool json) + private static string? Info(TextWriter w, TdbDocument doc, bool json, List infoWarnings) { var fields = new List>(); void Add(string key, object? value) => fields.Add(new(key, value)); @@ -252,7 +252,8 @@ private static Command Parse(string[] args) } catch (InvalidDataException e) { - error ??= e.Message; + // info did not read the tables before it counted drawings, so a failure to count them stays a warning. + infoWarnings.Add($"drawings are not counted: {e.Message}"); } try { @@ -323,12 +324,12 @@ private static Command Parse(string[] args) Output.WriteJson(w, j => { Output.WriteProperties(j, fields); - Output.WriteProperties(j, [new("warnings", doc.Warnings)]); + Output.WriteProperties(j, [new("warnings", (string[])[.. doc.Warnings, .. infoWarnings])]); }); } else { - Add("warnings", doc.Warnings.Count); + Add("warnings", doc.Warnings.Count + infoWarnings.Count); Output.WriteFields(w, fields); } return error; diff --git a/src/TdbIO/Db1Document.Tables.cs b/src/TdbIO/Db1Document.Tables.cs index 944bf00..868465b 100644 --- a/src/TdbIO/Db1Document.Tables.cs +++ b/src/TdbIO/Db1Document.Tables.cs @@ -1,3 +1,4 @@ +using System.Globalization; using TdbIO.Internal; namespace TdbIO; @@ -17,27 +18,24 @@ public IReadOnlyList ReadTables() => /// A new representing the decoded model object graph. public TeklaModel ReadModel() => ModelBuilder.Build(this); - /// Reads the drawing table (the section with key 27 and rows of 256 bytes) and decodes its rows. Builds a - /// new list on each call. - /// The drawings in file order; an empty list when the file has no drawing table. A file can hold text - /// sections only, with no table-section area after the id map at all; that is an empty list too. - /// The table-section area exists but a section in it is malformed, as - /// . + /// Reads the drawing table (the section with key 27 and rows of 256 bytes) and decodes its rows, leaving + /// out the deleted and superseded ones; decodes every row of the section. + /// Builds a new list on each call. + /// The drawings in file order; an empty list when the file has no drawing table. A file whose section + /// separators all open text sections has no table-section area; that is an empty list too. + /// The tables cannot be read, as , the drawing table + /// has rows of another size, or a text value of a drawing does not decode. public IReadOnlyList ReadDrawings() { - int first; - try + if (SectionWalker.HoldsOnlyTextSections(Payload.Span)) return []; + var tables = ReadTables().Where(s => s.Key == DrawingRow.TableKey).ToList(); + var section = tables.Find(s => s.RowSize == DrawingRow.ExpectedRowSize); + if (section is null && tables.Find(s => s.Rows.Count > 0) is { } other) { - first = SectionWalker.FindFirstSection(Payload.Span); + string problem = string.Create(CultureInfo.InvariantCulture, + $"the drawing table has rows of {other.RowSize} bytes, not {DrawingRow.ExpectedRowSize}"); + throw FormatError.At(problem, other.Offset); } - catch (InvalidDataException) - { - // No table-section area: the payload ends after the id map or holds text sections only. - return Array.Empty(); - } - - var section = SectionWalker.Walk(Payload, first, 0, SectionMode.Db1, null, _textEncoding) - .FirstOrDefault(s => s.Key == DrawingRow.TableKey && s.RowSize == DrawingRow.ExpectedRowSize); - return section?.AsDrawings() ?? Array.Empty(); + return section?.Rows.Where(r => !r.IsDeleted).Select(r => r.AsDrawing()).ToArray() ?? []; } } diff --git a/src/TdbIO/Internal/RowText.cs b/src/TdbIO/Internal/RowText.cs index 942d740..60fab95 100644 --- a/src/TdbIO/Internal/RowText.cs +++ b/src/TdbIO/Internal/RowText.cs @@ -13,6 +13,7 @@ private static readonly (int Key, int RowSize, (int At, int Width)[] Fields)[] T [ (AssemblyRow.TableKey, AssemblyRow.ExpectedRowSize, [(20, 64)]), (RelationRow.TableKey, RelationRow.ExpectedRowSize, [(16, 40)]), + (DrawingRow.TableKey, DrawingRow.ExpectedRowSize, [(8, 64), (100, 44), (144, 84)]), (PartAttrRow.TableKey, PartAttrRow.ExpectedRowSize, [(32, 22), (54, 62), (116, 62), (184, 22), (206, 62), (268, 32), (300, 62)]), (NumAttrAttrRow.TableKey, NumAttrAttrRow.ExpectedRowSize, [(16, 21)]), diff --git a/src/TdbIO/Internal/SectionWalker.cs b/src/TdbIO/Internal/SectionWalker.cs index 8b99b93..03aa9a1 100644 --- a/src/TdbIO/Internal/SectionWalker.cs +++ b/src/TdbIO/Internal/SectionWalker.cs @@ -36,6 +36,26 @@ internal static class SectionWalker 0xC9, 0xC0, 0xCE, 0xDB, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, ]; + /// True when there is at least one section separator after the header and every one opens a text section: + /// such a payload holds no table-section area. A text section begins with the same separator as a table section. + /// Its rows are skipped, because their bytes may hold the separator too. + public static bool HoldsOnlyTextSections(ReadOnlySpan payload) + { + bool text = false; + int at = BodyStart; + while (at < payload.Length) + { + int found = payload[at..].IndexOf(Separator); + if (found < 0) break; + at += found; + if (!TextSectionReader.StartsSection(payload[at..])) return false; + text = true; + at += TextSectionReader.SignatureLength; + while (at < payload.Length && payload[at] != 0) at += TextSectionReader.RowLength; + } + return text; + } + /// The offset of the first section of a .db1 payload: the first separator at or after 49, which must be /// preceded by the fixed 40-byte lead. public static int FindFirstSection(ReadOnlySpan payload) diff --git a/src/TdbIO/Internal/TextSectionReader.cs b/src/TdbIO/Internal/TextSectionReader.cs index 81253de..21fe1d1 100644 --- a/src/TdbIO/Internal/TextSectionReader.cs +++ b/src/TdbIO/Internal/TextSectionReader.cs @@ -24,6 +24,9 @@ internal static class TextSectionReader private static ReadOnlySpan Closer => [0x4F, 0x61, 0xBC, 0x00]; + /// True when begins with the signature of a text section. + public static bool StartsSection(ReadOnlySpan data) => data.StartsWith(Signature); + /// Every text section in file order. public static IReadOnlyList ReadAll(ReadOnlyMemory payload) { diff --git a/src/TdbIO/ModelRows.cs b/src/TdbIO/ModelRows.cs index 13d92e9..6edf4db 100644 --- a/src/TdbIO/ModelRows.cs +++ b/src/TdbIO/ModelRows.cs @@ -314,11 +314,11 @@ public static WeldingRow Decode(ReadOnlySpan body) /// and save times. The words the meaning of which is not known stay in the raw body (). /// The drawing identifier; the object of type 34 in table 1 with the same identifier. /// The object type code of the drawing; 34 in the samples. -/// The mark of the drawing (for example "G [6]", "C [W.20 - 1]"). +/// The mark of the drawing. /// The creation time of the drawing, as Unix seconds. /// The last modification time of the drawing, as Unix seconds, or 0 when there is none. -/// The file name of the drawing next to the model database (for example "D304d0d41-fe43-….dg"). -/// The type name of the drawing (for example "GA-drawing", "CAST UNIT - FRAME 4xA3", "BEAM"). +/// The name of the .dg file of the drawing, next to the model database. +/// The type name of the drawing. public readonly record struct DrawingRow( int Id, int ObjType, diff --git a/tests/TdbIO.Tests/CliTests.cs b/tests/TdbIO.Tests/CliTests.cs index ca9cc4e..49631fd 100644 --- a/tests/TdbIO.Tests/CliTests.cs +++ b/tests/TdbIO.Tests/CliTests.cs @@ -132,6 +132,7 @@ public void InfoOnModelDatabase() Assert.Equal(ContainerGuidText, f["modelGuid"]); Assert.Equal("1", f["idMapEntries"]); Assert.Equal("0xD", f["idMapField65"]); + Assert.Equal("0", f["drawings"]); Assert.Equal("1", f["textSections"]); Assert.Equal("2", f["textChains"]); Assert.Equal("1", f["saveStamps"]); @@ -233,16 +234,16 @@ private static byte[] DrawingRowBody() var body = new byte[DrawingRow.ExpectedRowSize]; BinaryPrimitives.WriteInt32LittleEndian(body.AsSpan(0), 1001); BinaryPrimitives.WriteInt32LittleEndian(body.AsSpan(4), 34); - Encoding.ASCII.GetBytes("G [1]").CopyTo(body.AsSpan(8)); - BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(88), 1708336801); + Encoding.ASCII.GetBytes("Mark [1]").CopyTo(body.AsSpan(8)); + BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(88), 1000000001); Encoding.ASCII.GetBytes("D00000000-0000-0000-0000-000000000000.dg").CopyTo(body.AsSpan(100)); - Encoding.ASCII.GetBytes("GA-drawing").CopyTo(body.AsSpan(144)); + Encoding.ASCII.GetBytes("Made-up type").CopyTo(body.AsSpan(144)); return body; } private string Db1WithDrawings() => File("d.db1", Gzip(Db1TablesPayload( Db1Section(null, 4, [1], (0x04, Counting(4), 1, 2)), - Db1Section(27, 256, [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], (0x04, DrawingRowBody(), 1, 2))))); + Db1Section(27, 256, [1], (0x04, DrawingRowBody(), 1, 2))))); [Fact] public void InfoCountsTheDrawingsOfTheDrawingTable() @@ -262,6 +263,49 @@ public void InfoCountsTheDrawingsOfTheDrawingTable() Assert.Equal("0", Fields(without)["drawings"]); } + [Fact] + public void InfoOnUnreadableTablesWarnsAndLeavesOutDrawings() + { + // A good drawing table before a section with a damaged closer: the drawings are not counted, a warning says + // why, and the exit code stays 0. + byte[] broken = Db1Section(99, 4, [1], (0x04, Counting(4), 1, 2)); + broken[^1] ^= 0xFF; + string path = File("broken_tables.db1", Gzip(Db1TablesPayload( + Db1Section(null, 4, [1]), Db1Section(27, 256, [1], (0x04, DrawingRowBody(), 1, 2)), broken))); + + var (exit, stdout, stderr) = Run("info", path); + Assert.Equal(Cli.ExitOk, exit); + var f = Fields(stdout); + Assert.False(f.ContainsKey("drawings")); + Assert.Equal("0", f["textSections"]); + Assert.Equal("1", f["warnings"]); + string warning = Assert.Single(Lines(stderr)); + Assert.StartsWith("tdbio: warning: drawings are not counted: ", warning); + Assert.Contains("closer", warning); + + var (jsonExit, jsonOut, _) = Run("info", path, "--json"); + Assert.Equal(Cli.ExitOk, jsonExit); + using var json = JsonDocument.Parse(jsonOut); + Assert.False(json.RootElement.TryGetProperty("drawings", out _)); + var listed = Assert.Single(json.RootElement.GetProperty("warnings").EnumerateArray()); + Assert.Equal(warning["tdbio: warning: ".Length..], listed.GetString()); + } + + [Fact] + public void InfoWarnsWhenTheTextOfADrawingDoesNotDecode() + { + byte[] body = DrawingRowBody(); + body[8] = 0xC0; + string path = File("text.db1", Gzip(Db1TablesPayload( + Db1Section(null, 4, [1]), Db1Section(27, 256, [1], (0x04, body, 1, 2))))); + + var (exit, stdout, stderr) = Run("info", path, "--encoding", "ascii"); + + Assert.Equal(Cli.ExitOk, exit); + Assert.False(Fields(stdout).ContainsKey("drawings")); + Assert.StartsWith("tdbio: warning: drawings are not counted: ", Assert.Single(Lines(stderr))); + } + // tables [Fact] diff --git a/tests/TdbIO.Tests/RowTextTests.cs b/tests/TdbIO.Tests/RowTextTests.cs index 6db0c66..a49dd8a 100644 --- a/tests/TdbIO.Tests/RowTextTests.cs +++ b/tests/TdbIO.Tests/RowTextTests.cs @@ -153,6 +153,25 @@ public void AShortValueTakesTheCodePageOfItsFile() Assert.Equal(["Колонна", "№5", "Ёж"], AssemblyNames(file)); } + [Theory] + [InlineData(8)] // mark + [InlineData(100)] // file name + [InlineData(144)] // type name + public void EveryDrawingTextFieldCountsForTheCodePageOfTheFile(int at) + { + // As above, with the Cyrillic letters in one text field of the drawing table only. + var letters = new byte[DrawingRow.ExpectedRowSize]; + Cp1251.GetBytes("Колонна").CopyTo(letters, at); + var number = new byte[DrawingRow.ExpectedRowSize]; + Cp1251.GetBytes("№5").CopyTo(number, 8); + var document = Db1Document.Create(Synthetic.Db1TablesPayload( + Synthetic.Db1Section(null, 4, [1]), + Synthetic.Db1Section(DrawingRow.TableKey, DrawingRow.ExpectedRowSize, [1], + (4, letters, 1, 1), (4, number, 1, 1)))); + + Assert.Equal("№5", document.ReadDrawings()[1].Mark); + } + [Fact] public void RowsOfTwoReadsOfTheSameFileAreEqual() { diff --git a/tests/TdbIO.Tests/SectionWalkerTests.cs b/tests/TdbIO.Tests/SectionWalkerTests.cs index 6816cec..363c6bc 100644 --- a/tests/TdbIO.Tests/SectionWalkerTests.cs +++ b/tests/TdbIO.Tests/SectionWalkerTests.cs @@ -264,6 +264,81 @@ public void Db1DocumentReadsItsTables() Assert.Equal(6, tables[1].Rows[0].B); } + // A drawing row with this mark; every other byte is zero. + private static (byte Marker, byte[] Body, int A, int B) DrawingTableRow(byte marker, string mark) + { + var body = new byte[DrawingRow.ExpectedRowSize]; + Ascii(mark).CopyTo(body, 8); + return (marker, body, 1, 2); + } + + [Fact] + public void ReadDrawingsSkipsDeletedAndSupersededRows() + { + var document = Db1Document.Create(Db1TablesPayload( + Db1Section(null, 4, [1]), + Db1Section(DrawingRow.TableKey, DrawingRow.ExpectedRowSize, [1], + DrawingTableRow(0x0C, "A old"), DrawingTableRow(0x04, "A new"), DrawingTableRow(0x0C, "B gone")))); + + Assert.Equal(["A new"], document.ReadDrawings().Select(d => d.Mark)); + // The bulk decoder keeps every row, as the other bulk decoders do. + Assert.Equal(3, document.ReadTables()[1].AsDrawings().Count); + } + + [Fact] + public void ReadDrawingsWithADamagedLeadThrows() + { + byte[] payload = Db1TablesPayload(Db1Section(null, 4, [1])); + payload[payload.Length - 17 - 1] = 0; // last byte of the lead + + var e = Assert.Throws(() => Db1Document.Create(payload).ReadDrawings()); + Assert.Contains("lead", e.Message); + } + + [Fact] + public void ReadDrawingsOfTextSectionsWithoutATableAreaIsEmpty() + { + // A text section opens with the bytes of the table section separator, and still is no table area. The text of a + // row may hold these bytes too. + byte[] payload = Concat(XsteelHead(), IdMapBody([]), + TextSectionBytes(ChainRows(1, 3, Ascii("One"))), TextSectionBytes(ChainRows(10, 3, SectionSeparator))); + + Assert.Empty(Db1Document.Create(payload).ReadDrawings()); + } + + [Fact] + public void ReadDrawingsDoesNotTakeALeadingTextSectionForTheWholeFile() + { + // Here the first separator opens a text section but a table section follows: tables that cannot be read, not a + // file without drawings. + byte[] payload = Concat(XsteelHead(), IdMapBody([]), TextSectionBytes(ChainRows(1, 3, Ascii("One"))), + FirstSectionLead(), Db1Section(null, 4, [1])); + + Assert.Throws(() => Db1Document.Create(payload).ReadDrawings()); + } + + [Fact] + public void ReadDrawingsWithNoSeparatorAtAllThrows() + { + // The lead with nothing after it: tables that cannot be read, not a file without drawings. + Assert.Throws(() => Db1Document.Create(Db1TablesPayload()).ReadDrawings()); + } + + [Fact] + public void ReadDrawingsOfADrawingTableWithRowsOfAnotherSizeThrows() + { + var document = Db1Document.Create(Db1TablesPayload( + Db1Section(null, 4, [1]), Db1Section(DrawingRow.TableKey, 8, [1], (0x04, Counting(8), 1, 2)))); + + var e = Assert.Throws(() => document.ReadDrawings()); + Assert.Contains("rows of 8 bytes", e.Message); + Assert.Equal(document.ReadTables()[1].Offset, e.Offset); + + // A section of another size without rows holds no drawing. + Assert.Empty(Db1Document.Create(Db1TablesPayload( + Db1Section(null, 4, [1]), Db1Section(DrawingRow.TableKey, 8, [1]))).ReadDrawings()); + } + [Fact] public void DbvSectionsReadUnsignedNumbersAndAnyType() { diff --git a/tests/TdbIO.Tests/TableRowDecoderTests.cs b/tests/TdbIO.Tests/TableRowDecoderTests.cs index 307525d..848aa3f 100644 --- a/tests/TdbIO.Tests/TableRowDecoderTests.cs +++ b/tests/TdbIO.Tests/TableRowDecoderTests.cs @@ -110,29 +110,29 @@ public void AssemblyRowTextWithAnUndefinedByteIsAnErrorAtItsOffset() Assert.Equal(21, e.Offset); Assert.Contains("cp1251", e.Message); } + [Fact] public void DrawingRowDecodesMarkFileNameTypeAndTimes() { - // The layout of the drawing table (table 27, size 256) is section 1.11 of the format notes of the project. var row = MakeRow(DrawingRow.ExpectedRowSize, span => { - BinaryPrimitives.WriteInt32LittleEndian(span[0..], 97358816); + BinaryPrimitives.WriteInt32LittleEndian(span[0..], 1001); BinaryPrimitives.WriteInt32LittleEndian(span[4..], 34); - Encoding.ASCII.GetBytes("G [6]").CopyTo(span[8..]); - BinaryPrimitives.WriteUInt32LittleEndian(span[88..], 1708336801); - BinaryPrimitives.WriteUInt32LittleEndian(span[92..], 1711022910); - Encoding.ASCII.GetBytes("D83a6d6c9-dd0c-4bbd-b977-553b6cf3701c.dg").CopyTo(span[100..]); - Encoding.ASCII.GetBytes("GA-drawing").CopyTo(span[144..]); + Encoding.ASCII.GetBytes("Mark [1]").CopyTo(span[8..]); + BinaryPrimitives.WriteUInt32LittleEndian(span[88..], 1000000001); + BinaryPrimitives.WriteUInt32LittleEndian(span[92..], 1000000002); + Encoding.ASCII.GetBytes("D11111111-2222-4333-8444-555555555555.dg").CopyTo(span[100..]); + Encoding.ASCII.GetBytes("Made-up type").CopyTo(span[144..]); }); var drawing = row.AsDrawing(); - Assert.Equal(97358816, drawing.Id); + Assert.Equal(1001, drawing.Id); Assert.Equal(34, drawing.ObjType); - Assert.Equal("G [6]", drawing.Mark); - Assert.Equal(1708336801u, drawing.CreatedAt); - Assert.Equal(1711022910u, drawing.ModifiedAt); - Assert.Equal("D83a6d6c9-dd0c-4bbd-b977-553b6cf3701c.dg", drawing.FileName); - Assert.Equal("GA-drawing", DrawingRow.Decode(row.Body.Span).TypeName); + Assert.Equal("Mark [1]", drawing.Mark); + Assert.Equal(1000000001u, drawing.CreatedAt); + Assert.Equal(1000000002u, drawing.ModifiedAt); + Assert.Equal("D11111111-2222-4333-8444-555555555555.dg", drawing.FileName); + Assert.Equal("Made-up type", DrawingRow.Decode(row.Body.Span).TypeName); } [Fact]