void WriteInt(this byte[] arr, int offset, int value, bool little) { #if SAFE_CAST fixed(byte *bs = arr) { int *target = (int *)(bs + offset); (*target) = value; } if (BitConverter.IsLittleEndian != little) { Reverse(arr, offset, 4); } #else if (BitConverter.IsLittleEndian == little) { Int32Field fs = new Int32Field(value); fs.Fill(arr, offset); } else { RInt32Field fs = new RInt32Field(value); fs.Fill(arr, offset); } #endif }
void WriteStreamInt(this Stream stream, int offset, int value, bool little) { #if SAFE_CAST byte[] intBytes = new byte[4]; fixed(byte *bs = intBytes) { int *c = (int *)bs; *c = value; if (BitConverter.IsLittleEndian != little) { Reverse4(c); } } stream.Position = offset; stream.Write(intBytes, 0, intBytes.Length); #else if (BitConverter.IsLittleEndian == little) { Int32Field fs = new Int32Field(value); fs.Fill(stream, offset); } else { RInt32Field fs = new RInt32Field(value); fs.Fill(stream, offset); } #endif }