Example #1
0
        long ReadStreamLong(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)
            {
                long *c = (long *)bs;

                return(*c);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                LongField fs = new LongField(stream, offset);
                return(fs.LongVal);
            }
            else
            {
                RLongField fs = new RLongField(stream, offset);
                return(fs.LongVal);
            }
#endif
        }
Example #2
0
        void WriteStreamLong(this Stream stream, int offset, long value, bool little)
        {
#if SAFE_CAST
            byte[] intBytes = new byte[8];

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

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

            stream.Position = offset;
            stream.Write(intBytes, 0, intBytes.Length);
#else
            if (BitConverter.IsLittleEndian == little)
            {
                LongField fs = new LongField(value);
                fs.Fill(stream, offset);
            }
            else
            {
                RLongField fs = new RLongField(value);
                fs.Fill(stream, offset);
            }
#endif
        }
Example #3
0
        void WriteLong(this byte[] arr, int offset, long value, bool little)
        {
#if SAFE_CAST
            fixed(byte *bs = arr)
            {
                long *target = (long *)(bs + offset);

                (*target) = value;
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse(arr, offset, 8);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                LongField fs = new LongField(value);
                fs.Fill(arr, offset);
            }
            else
            {
                RLongField fs = new RLongField(value);
                fs.Fill(arr, offset);
            }
#endif
        }
Example #4
0
        long ReadLong(this byte[] arr, int offset, bool little)
        {
#if SAFE_CAST
#if PROFILER
            Profiler.BeginSample("ReadLong");
#endif

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

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

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