void WriteStreamULong(this Stream stream, int offset, ulong value, bool little) { #if SAFE_CAST byte[] intBytes = new byte[8]; fixed(byte *bs = intBytes) { ulong *c = (ulong *)bs; *c = value; if (BitConverter.IsLittleEndian != little) { Reverse8(c); } } stream.Position = offset; stream.Write(intBytes, 0, intBytes.Length); #else if (BitConverter.IsLittleEndian == little) { ULongField fs = new ULongField(value); fs.Fill(stream, offset); } else { RULongField fs = new RULongField(value); fs.Fill(stream, offset); } #endif }
void WriteULong(this byte[] arr, int offset, ulong value, bool little) { #if SAFE_CAST fixed(byte *bs = arr) { ulong *target = (ulong *)(bs + offset); (*target) = value; } if (BitConverter.IsLittleEndian != little) { Reverse(arr, offset, 8); } #else if (BitConverter.IsLittleEndian == little) { ULongField fs = new ULongField(value); fs.Fill(arr, offset); } else { RULongField fs = new RULongField(value); fs.Fill(arr, offset); } #endif }