Пример #1
0
        ulong ReadStreamULong(this Stream stream, int offset, bool little)
        {
#if SAFE_CAST
            byte[] intBytes = new byte[8];
            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)
            {
                ULongField fs = new ULongField(stream, offset);
                return(fs.ULongVal);
            }
            else
            {
                RULongField fs = new RULongField(stream, offset);
                return(fs.ULongVal);
            }
#endif
        }
Пример #2
0
        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
        }
Пример #3
0
        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
        }
Пример #4
0
        ulong ReadULong(this byte[] arr, int offset, bool little)
        {
#if SAFE_CAST
#if PROFILER
            Profiler.BeginSample("ReadULong");
#endif

            ulong val;
            fixed(byte *bytes = arr)
            {
                byte *databytes = bytes + offset;

                val = *((ulong *)databytes);
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse8(&val);
            }
#if PROFILER
            Profiler.EndSample();
#endif
            return(val);
#else
            if (BitConverter.IsLittleEndian == little)
            {
                ULongField fs = new ULongField(arr, offset);
                return(fs.ULongVal);
            }
            else
            {
                RULongField fs = new RULongField(arr, offset);
                return(fs.ULongVal);
            }
#endif
        }