I think this code will cause an ‘little-endian vs big-endian’ issue between platforms.
Is the platform using big-endian gone?
internal unsafe void WriteUnmanaged<T>(in T value) where T : unmanaged
{
fixed (T* ptr = &value)
{
byte* bytes = (byte*)ptr;
WriteBytes(bytes, sizeof(T));
}
}
public unsafe void WriteBytes(byte* value, int size, int offset = 0)
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
if (Handle->InBitwiseContext)
{
throw new InvalidOperationException(
"Cannot use BufferWriter in bytewise mode while in a bitwise context.");
}
if (Handle->Position + size > Handle->AllowedWriteMark)
{
throw new OverflowException($"Attempted to write without first calling {nameof(TryBeginWrite)}()");
}
#endif
UnsafeUtility.MemCpy((Handle->BufferPointer + Handle->Position), value + offset, size);
Handle->Position += size;
}
Endianness can certainly be different between devices. You may have spotted a potential issue here. Please report it on the Netcode github repository:
Slim chance that perhaps UnsafeUtility.MemCpy takes care of this internally. Or the endianess correction can also be done on the receiving end. Check the corresponding “ReadBytes” methods.
public unsafe void ReadBytes(byte* value, int size, int offset = 0)
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
if (Handle->InBitwiseContext)
{
throw new InvalidOperationException(
"Cannot use BufferReader in bytewise mode while in a bitwise context.");
}
if (Handle->Position + size > Handle->AllowedReadMark)
{
throw new OverflowException($"Attempted to read without first calling {nameof(TryBeginRead)}()");
}
#endif
UnsafeUtility.MemCpy(value + offset, (Handle->BufferPointer + Handle->Position), size);
Handle->Position += size;
}