Beispiel #1
0
        char ReadStreamChar(this Stream stream, int offset, bool little)
        {
#if SAFE_CAST
            byte[] intBytes = new byte[2];
            stream.Position = offset;
            stream.Read(intBytes, 0, intBytes.Length);

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse(intBytes, 0, intBytes.Length);
            }

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

                return(*c);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                CharField fs = new CharField(stream, offset);
                return(fs.CharVal);
            }
            else
            {
                RCharField fs = new RCharField(stream, offset);
                return(fs.CharVal);
            }
#endif
        }
Beispiel #2
0
        void WriteStreamChar(this Stream stream, int offset, char value, bool little)
        {
#if SAFE_CAST
            byte[] intBytes = new byte[2];

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

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

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

                (*target) = value;
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse(arr, offset, 2);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                CharField fs = new CharField(value);
                fs.Fill(arr, offset);
            }
            else
            {
                RCharField fs = new RCharField(value);
                fs.Fill(arr, offset);
            }
#endif
        }
Beispiel #4
0
        char ReadChar(this byte[] arr, int offset, bool little)
        {
#if SAFE_CAST
#if PROFILER
            Profiler.BeginSample("ReadChar");
#endif

            char s;
            fixed(byte *bytes = arr)
            {
                char *databytes = (char *)(bytes + offset);

                s = *databytes;
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse2(&s);
            }

#if PROFILER
            Profiler.EndSample();
#endif
            return(s);
#else
            if (BitConverter.IsLittleEndian == little)
            {
                CharField fs = new CharField(arr, offset);
                return(fs.CharVal);
            }
            else
            {
                RCharField fs = new RCharField(arr, offset);
                return(fs.CharVal);
            }
#endif
        }