Ejemplo n.º 1
0
        uint ReadStreamUInt(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)
            {
                uint *c = (uint *)bs;

                return(*c);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                Uint32Field fs = new Uint32Field(stream, offset);
                return(fs.UintVal);
            }
            else
            {
                RUint32Field fs = new RUint32Field(stream, offset);
                return(fs.UintVal);
            }
#endif
        }
Ejemplo n.º 2
0
        uint ReadUInt(this byte[] arr, int offset, bool little)
        {
#if SAFE_CAST
#if PROFILER
            Profiler.BeginSample("ReadUInt");
#endif
            uint result;
            fixed(byte *bytes = arr)
            {
                byte *uintbytes = bytes + offset;

                result = *((uint *)uintbytes);
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse4(&result);
            }
#if PROFILER
            Profiler.EndSample();
#endif
            return(result);
#else
            if (BitConverter.IsLittleEndian == little)
            {
                Uint32Field fs = new Uint32Field(arr, offset);
                return(fs.UintVal);
            }
            else
            {
                RUint32Field fs = new RUint32Field(arr, offset);
                return(fs.UintVal);
            }
#endif
        }
Ejemplo n.º 3
0
        void WriteStreamUInt(this Stream stream, int offset, uint value, bool little)
        {
#if SAFE_CAST
            byte[] intBytes = new byte[4];

            fixed(byte *bs = intBytes)
            {
                uint *c = (uint *)bs;

                *c = value;
                if (BitConverter.IsLittleEndian != little)
                {
                    Reverse4(c);
                }
            }

            stream.Position = offset;
            stream.Write(intBytes, 0, intBytes.Length);
#else
            if (BitConverter.IsLittleEndian == little)
            {
                Uint32Field fs = new Uint32Field(value);
                fs.Fill(stream, offset);
            }
            else
            {
                RUint32Field fs = new RUint32Field(value);
                fs.Fill(stream, offset);
            }
#endif
        }
Ejemplo n.º 4
0
        void WriteUInt(this byte[] arr, int offset, uint value, bool little)
        {
#if SAFE_CAST
            fixed(byte *bs = arr)
            {
                uint *target = (uint *)(bs + offset);

                (*target) = value;
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse(arr, offset, 4);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                Uint32Field fs = new Uint32Field(value);
                fs.Fill(arr, offset);
            }
            else
            {
                RUint32Field fs = new RUint32Field(value);
                fs.Fill(arr, offset);
            }
#endif
        }