Skip to content

Commit

Permalink
Merge pull request #98 from Haselnussbomber/subrow-readcolumn
Browse files Browse the repository at this point in the history
Copy over ReadColumn to RawSubrow
  • Loading branch information
NotAdam authored Nov 15, 2024
2 parents f96f062 + bdc98cc commit 2984b58
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Lumina/Excel/RawSubrow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ public readonly struct RawSubrow( ExcelPage page, uint offset, uint row, ushort
public ushort GetColumnOffset( int columnIdx ) =>
page.Sheet.GetColumnOffset( columnIdx );

/// <summary>
/// Reads the value of the specified column.
/// </summary>
/// <param name="columnIdx"></param>
/// <returns>Returns the value as a boxed <see langword="object"/>.</returns>
/// <exception cref="InvalidOperationException">Thrown when the column is of an unknown type.</exception>
public object ReadColumn( int columnIdx )
{
var column = page.Sheet.Columns[columnIdx];
return column.Type switch
{
ExcelColumnDataType.String => ReadString( column.Offset ),
ExcelColumnDataType.Bool => ReadBool( column.Offset ),
ExcelColumnDataType.Int8 => ReadInt8( column.Offset ),
ExcelColumnDataType.UInt8 => ReadUInt8( column.Offset ),
ExcelColumnDataType.Int16 => ReadInt16( column.Offset ),
ExcelColumnDataType.UInt16 => ReadUInt16( column.Offset ),
ExcelColumnDataType.Int32 => ReadInt32( column.Offset ),
ExcelColumnDataType.UInt32 => ReadUInt32( column.Offset ),
ExcelColumnDataType.Float32 => ReadFloat32( column.Offset ),
ExcelColumnDataType.Int64 => ReadInt64( column.Offset ),
ExcelColumnDataType.UInt64 => ReadUInt64( column.Offset ),
>= ExcelColumnDataType.PackedBool0 and <= ExcelColumnDataType.PackedBool7 =>
page.ReadPackedBool( column.Offset, (byte)( column.Type - ExcelColumnDataType.PackedBool0 ) ),
_ => throw new InvalidOperationException( $"Unknown column type {column.Type}" )
};
}

/// <inheritdoc cref="RawRow.ReadString(nuint)"/>
public ReadOnlySeString ReadString( nuint offset ) =>
page.ReadString( Offset + offset, Offset );
Expand Down

0 comments on commit 2984b58

Please sign in to comment.