From bdc98cc708425fc86ffded081ecca7dee5571e1c Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Thu, 14 Nov 2024 17:39:39 +0100 Subject: [PATCH] Copy over ReadColumn to RawSubrow --- src/Lumina/Excel/RawSubrow.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Lumina/Excel/RawSubrow.cs b/src/Lumina/Excel/RawSubrow.cs index abf84613..c078403d 100644 --- a/src/Lumina/Excel/RawSubrow.cs +++ b/src/Lumina/Excel/RawSubrow.cs @@ -34,6 +34,34 @@ public readonly struct RawSubrow( ExcelPage page, uint offset, uint row, ushort public ushort GetColumnOffset( int columnIdx ) => page.Sheet.GetColumnOffset( columnIdx ); + /// + /// Reads the value of the specified column. + /// + /// + /// Returns the value as a boxed . + /// Thrown when the column is of an unknown type. + 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}" ) + }; + } + /// public ReadOnlySeString ReadString( nuint offset ) => page.ReadString( Offset + offset, Offset );