Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy over ReadColumn to RawSubrow #98

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading