Skip to content

Commit

Permalink
Merge pull request #29 from KalopsiaTwilight/fix-wdc1
Browse files Browse the repository at this point in the history
Fix Reference Data writing in WDC1 / WDC2
  • Loading branch information
Marlamin authored Jan 6, 2025
2 parents 1868449 + 5419841 commit bcb1de6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
33 changes: 18 additions & 15 deletions DBCD.IO/Writers/WDC1Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,30 @@ public void Serialize(int id, T row)

int fieldIndex = i - indexFieldOffSet;

// relationship field, used for faster lookup on IDs
if (info.IsNonInlineRelation)
// reference data field
if (fieldIndex >= m_writer.Meta.Length)
{
m_writer.ReferenceData.Add((int)Convert.ChangeType(info.Getter(row), typeof(int)));
continue;
}

// relationship field, used for faster lookup on IDs
if (info.IsRelation)
m_writer.ReferenceData.Add((int)Convert.ChangeType(info.Getter(row), typeof(int)));

if (info.IsArray)
{
if (arrayWriters.TryGetValue(info.FieldType, out var writer))
writer(bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], (Array)info.Getter(row));
else
throw new Exception("Unhandled array type: " + typeof(T).Name);
}
else
{
if (info.IsArray)
{
if (arrayWriters.TryGetValue(info.FieldType, out var writer))
writer(bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], (Array)info.Getter(row));
else
throw new Exception("Unhandled array type: " + typeof(T).Name);
}
if (simpleWriters.TryGetValue(info.FieldType, out var writer))
writer(id, bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], info.Getter(row));
else
{
if (simpleWriters.TryGetValue(info.FieldType, out var writer))
writer(id, bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], info.Getter(row));
else
throw new Exception("Unhandled field type: " + typeof(T).Name);
}
throw new Exception("Unhandled field type: " + typeof(T).Name);
}
}

Expand Down
34 changes: 19 additions & 15 deletions DBCD.IO/Writers/WDC2Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,31 @@ public void Serialize(int id, T row)

int fieldIndex = i - indexFieldOffSet;

// relationship field, used for faster lookup on IDs
if (info.IsNonInlineRelation)
// reference data field
if (fieldIndex >= m_writer.Meta.Length)
{
m_writer.ReferenceData.Add((int)Convert.ChangeType(info.Getter(row), typeof(int)));
continue;
}

// relationship field, used for faster lookup on IDs
if (info.IsRelation)
m_writer.ReferenceData.Add((int)Convert.ChangeType(info.Getter(row), typeof(int)));


if (info.IsArray)
{
if (arrayWriters.TryGetValue(info.FieldType, out var writer))
writer(bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], (Array)info.Getter(row));
else
throw new Exception("Unhandled array type: " + typeof(T).Name);
}
else
{
if (info.IsArray)
{
if (arrayWriters.TryGetValue(info.FieldType, out var writer))
writer(bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], (Array)info.Getter(row));
else
throw new Exception("Unhandled array type: " + typeof(T).Name);
}
if (simpleWriters.TryGetValue(info.FieldType, out var writer))
writer(id, bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], info.Getter(row));
else
{
if (simpleWriters.TryGetValue(info.FieldType, out var writer))
writer(id, bitWriter, m_writer, m_fieldMeta[fieldIndex], ColumnMeta[fieldIndex], PalletData[fieldIndex], CommonData[fieldIndex], info.Getter(row));
else
throw new Exception("Unhandled field type: " + typeof(T).Name);
}
throw new Exception("Unhandled field type: " + typeof(T).Name);
}
}

Expand Down

0 comments on commit bcb1de6

Please sign in to comment.