READER BOYS

This commit is contained in:
vis2k 2022-01-15 00:27:51 +08:00
parent bba19425e9
commit 9e0db322ef

View File

@ -95,6 +95,9 @@ internal unsafe T ReadBlittable<T>()
throw new EndOfStreamException($"ReadBlittable<{typeof(T)}> out of range: {ToString()}"); throw new EndOfStreamException($"ReadBlittable<{typeof(T)}> out of range: {ToString()}");
} }
// TODO TRY
T* valueBuffer = stackalloc T[1];
// read blittable // read blittable
T value; T value;
fixed (byte* ptr = &buffer.Array[buffer.Offset + Position]) fixed (byte* ptr = &buffer.Array[buffer.Offset + Position])
@ -102,7 +105,13 @@ internal unsafe T ReadBlittable<T>()
// cast buffer to a T* pointer and then read from it. // cast buffer to a T* pointer and then read from it.
// note: this failed on android before. // note: this failed on android before.
// supposedly works with 2020.3 LTS though. // supposedly works with 2020.3 LTS though.
value = *(T*)ptr; //value = *(T*)ptr;
// copy possibly unaligned buffer @ position to aligned value buffer
UnsafeUtility.MemCpy(valueBuffer, ptr, size);
// and extract the value
value = valueBuffer[0];
} }
Position += size; Position += size;
return value; return value;