Skip to content

Commit

Permalink
Add bit size of column attribute to type information
Browse files Browse the repository at this point in the history
  • Loading branch information
KalopsiaTwilight committed Jan 5, 2025
1 parent 723f901 commit 1af829e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions DBCD.IO/Attributes/SizeInBitsAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DBCD.IO.Attributes
{
public class SizeInBitsAttribute: Attribute
{
public readonly ushort Size;

public SizeInBitsAttribute(ushort size) => Size = size;
}
}
4 changes: 4 additions & 0 deletions DBCD.IO/DBParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("DBCD")]

namespace DBCD.IO
{
Expand All @@ -23,6 +26,7 @@ public class DBParser
public uint LayoutHash => _reader.LayoutHash;
public int IdFieldIndex => _reader.IdFieldIndex;
public DB2Flags Flags => _reader.Flags;
internal ColumnMetaData[] ColumnMeta => _reader.ColumnMeta;
#endregion

public DBParser(string fileName) : this(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { }
Expand Down
10 changes: 10 additions & 0 deletions DBCD/DBCDBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ internal Tuple<Type, DBCDInfo> Build(DBParser dbcReader, Stream dbd, string name
var columns = new List<string>(fields.Length);
bool localiseStrings = locale != Locale.None;

var metadataIndex = 0;
foreach (var fieldDefinition in fields)
{
var columnDefinition = databaseDefinition.columnDefinitions[fieldDefinition.name];
Expand All @@ -100,6 +101,15 @@ internal Tuple<Type, DBCDInfo> Build(DBParser dbcReader, Stream dbd, string name
if (fieldDefinition.isID)
{
AddAttribute<IndexAttribute>(field, fieldDefinition.isNonInline);
}

if (!fieldDefinition.isNonInline)
{
if (metadataIndex < dbcReader.ColumnMeta.Length)
{
AddAttribute<SizeInBitsAttribute>(field, dbcReader.ColumnMeta[metadataIndex].Size);
}
metadataIndex++;
}

if (fieldDefinition.arrLength > 1)
Expand Down

0 comments on commit 1af829e

Please sign in to comment.