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 }
int ReadStreamInt(this Stream stream, int offset, bool little) { #if SAFE_CAST byte[] intBytes = new byte[4]; stream.Position = offset; stream.Read(intBytes, 0, intBytes.Length); if (BitConverter.IsLittleEndian != little) { Reverse(intBytes, 0, intBytes.Length); } fixed(byte *bs = intBytes) { int *c = (int *)bs; return(*c); } #else if (BitConverter.IsLittleEndian == little) { Int32Field fs = new Int32Field(stream, offset); return(fs.IntVal); } else { RInt32Field fs = new RInt32Field(stream, offset); return(fs.IntVal); } #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 }
int ReadInt(this byte[] arr, int offset, bool little) { #if SAFE_CAST #if PROFILER Profiler.BeginSample("ReadInt"); #endif int result; fixed(byte *bytes = arr) { byte *intbytes = bytes + offset; int * intptr = (int *)intbytes; result = *intptr; } if (BitConverter.IsLittleEndian != little) { Reverse4(&result); } #if PROFILER Profiler.EndSample(); #endif return(result); #else if (BitConverter.IsLittleEndian == little) { Int32Field fs = new Int32Field(arr, offset); return(fs.IntVal); } else { RInt32Field fs = new RInt32Field(arr, offset); return(fs.IntVal); } #endif }