Provides static methods for converting primitive types to and from little-endian byte representation.
コード例 #1
0
 /// <inheritdoc />
 public bool TryReadUInt64(out ulong value)
 {
     if (CanAdvance(8))
     {
         int start = UncheckedAdvance(8);
         value = LittleEndianBitConverter.ToUInt64(_buffer, start);
         return(true);
     }
     else
     {
         return(Misc.Fail(out value));
     }
 }
コード例 #2
0
 /// <inheritdoc />
 public bool TryReadInt32(out int value)
 {
     if (CanAdvance(4))
     {
         int start = UncheckedAdvance(4);
         value = LittleEndianBitConverter.ToInt32(_buffer, start);
         return(true);
     }
     else
     {
         return(Misc.Fail(out value));
     }
 }
コード例 #3
0
        private bool TryReadInt16(out short value, bool peek)
        {
            if (CanAdvance(2))
            {
                int start = _currentOffset;
                if (!peek)
                {
                    UncheckedAdvance(2);
                }

                value = LittleEndianBitConverter.ToInt16(_buffer, start);
                return(true);
            }
            else
            {
                return(Misc.Fail(out value));
            }
        }
コード例 #4
0
        private short ReadInt16(bool peek)
        {
            int start;

            if (peek)
            {
                // If we just wanna peek, don't advance.
                if (!CanAdvance(2))
                {
                    throw PacketReadingException.EndOfStream();
                }

                start = _currentOffset;
            }
            else
            {
                // Otherwise do advance.
                start = CheckedAdvance(2);
            }

            return(LittleEndianBitConverter.ToInt16(_buffer, start));
        }
コード例 #5
0
        /// <inheritdoc />
        /// <inheritdoc cref="CheckedAdvance" select="exception[@cref='PacketReadingException']" />
        public ulong ReadUInt64()
        {
            int start = CheckedAdvance(8);

            return(LittleEndianBitConverter.ToUInt64(_buffer, start));
        }
コード例 #6
0
        /// <inheritdoc />
        /// <inheritdoc cref="CheckedAdvance" select="exception[@cref='PacketReadingException']" />
        public uint ReadUInt32()
        {
            int start = CheckedAdvance(4);

            return(LittleEndianBitConverter.ToUInt32(_buffer, start));
        }
コード例 #7
0
        /// <inheritdoc />
        /// <inheritdoc cref="CheckedAdvance" select="exception[@cref='PacketReadingException']" />
        public ushort ReadUInt16()
        {
            int start = CheckedAdvance(2);

            return(LittleEndianBitConverter.ToUInt16(_buffer, start));
        }
コード例 #8
0
        /// <inheritdoc />
        /// <inheritdoc cref="ThrowIfDisposed()" select="exception[@cref='ObjectDisposedException']" />
        public void WriteInt16(ushort number)
        {
            ThrowIfDisposed();

            WriteDirect(LittleEndianBitConverter.GetBytes(number));
        }
コード例 #9
0
        /// <inheritdoc />
        /// <inheritdoc cref="ThrowIfDisposed()" select="exception[@cref='ObjectDisposedException']" />
        public void WriteBoolean(bool boolean)
        {
            ThrowIfDisposed();

            WriteDirect(LittleEndianBitConverter.GetBytes(boolean));
        }