Fix number marshaling for PDT variable memory.

This commit is contained in:
2022-11-06 13:46:23 +08:00
parent 2c74296532
commit fc04071b53

View File

@@ -46,7 +46,7 @@ namespace Cryville.Common.Pdt {
/// <returns>A number.</returns>
/// <exception cref="InvalidCastException">The span at the offset does not represent a number.</exception>
public float AsNumber(int offset = 0) {
if (Type != PdtInternalType.Number)
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
throw new InvalidCastException("Not a number");
float value;
byte* ptr = (byte*)&value;
@@ -62,7 +62,7 @@ namespace Cryville.Common.Pdt {
/// <exception cref="InvalidCastException">The span at the offset does not represent a number.</exception>
/// <exception cref="InvalidOperationException">The length of the span is not sufficient.</exception>
public void SetNumber(float value, int offset = 0) {
if (Type != PdtInternalType.Number)
if (Type != PdtInternalType.Number && Type != PdtInternalType.Vector)
throw new InvalidCastException("Not a number");
if (Length < sizeof(float) + offset)
throw new InvalidOperationException("Frame length not sufficient");