示例#1
0
        void WriteStreamUShort(this Stream stream, int offset, ushort value, bool little)
        {
#if SAFE_CAST
            byte[] intBytes = new byte[2];

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

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

            stream.Position = offset;
            stream.Write(intBytes, 0, intBytes.Length);
#else
            if (BitConverter.IsLittleEndian == little)
            {
                UShortField fs = new UShortField(value);
                fs.Fill(stream, offset);
            }
            else
            {
                RUShortField fs = new RUShortField(value);
                fs.Fill(stream, offset);
            }
#endif
        }
示例#2
0
        void WriteUShort(this byte[] arr, int offset, ushort value, bool little)
        {
#if SAFE_CAST
            fixed(byte *bs = arr)
            {
                ushort *target = (ushort *)(bs + offset);

                (*target) = value;
            }

            if (BitConverter.IsLittleEndian != little)
            {
                Reverse(arr, offset, 2);
            }
#else
            if (BitConverter.IsLittleEndian == little)
            {
                UShortField fs = new UShortField(value);
                fs.Fill(arr, offset);
            }
            else
            {
                RUShortField fs = new RUShortField(value);
                fs.Fill(arr, offset);
            }
#endif
        }