示例#1
0
        /// <summary>
        /// Writes a fixed-length ASCII-encoded string value to the underlying stream. To fit (size), the string content is either truncated or padded with null characters.
        /// </summary>
        public void WriteAsciiFixed(string value, int size)
        {
            if (value == null)
            {
                Console.WriteLine("Network: Attempted to WriteAsciiFixed() with null value");
                value = string.Empty;
            }

            int length = value.Length;

            UnderlyingStream.SetLength(UnderlyingStream.Length + size);

            if (length >= size)
            {
                UnderlyingStream.Position += Encoding.ASCII.GetBytes(value, 0, size, UnderlyingStream.GetBuffer(), (int)UnderlyingStream.Position);
            }
            else
            {
                Encoding.ASCII.GetBytes(value, 0, length, UnderlyingStream.GetBuffer(), (int)UnderlyingStream.Position);
                UnderlyingStream.Position += size;
            }

            /*byte[] buffer = Encoding.ASCII.GetBytes( value );
             *
             * if ( buffer.Length >= size )
             * {
             *      m_Stream.Write( buffer, 0, size );
             * }
             * else
             * {
             *      m_Stream.Write( buffer, 0, buffer.Length );
             *      Fill( size - buffer.Length );
             * }*/
        }
示例#2
0
        ///<inheritdoc />
        public override void SetLength(long length)
        {
            ThrowIfDisposed();

            if (_memoryStatus == MemoryFlag.AutoOverFlowToDisk && _isInMemory && length > _threshholdSize)
            {
                OverflowToPersistentStream();
            }

            UnderlyingStream.SetLength(length);
        }
示例#3
0
 /// <summary>
 /// Writes a number of 0x00 byte values to the underlying stream.
 /// </summary>
 public void Fill(int length)
 {
     if (UnderlyingStream.Position == UnderlyingStream.Length)
     {
         UnderlyingStream.SetLength(UnderlyingStream.Length + length);
         UnderlyingStream.Seek(0, SeekOrigin.End);
     }
     else
     {
         UnderlyingStream.Write(new byte[length], 0, length);
     }
 }
示例#4
0
        /// <summary>
        /// Writes a dynamic-length ASCII-encoded string value to the underlying stream, followed by a 1-byte null character.
        /// </summary>
        public void WriteAsciiNull(string value)
        {
            if (value == null)
            {
                Console.WriteLine("Network: Attempted to WriteAsciiNull() with null value");
                value = string.Empty;
            }

            int length = value.Length;

            UnderlyingStream.SetLength(UnderlyingStream.Length + length + 1);

            Encoding.ASCII.GetBytes(value, 0, length, UnderlyingStream.GetBuffer(), (int)UnderlyingStream.Position);
            UnderlyingStream.Position += length + 1;

            /*byte[] buffer = Encoding.ASCII.GetBytes( value );
             *
             * m_Stream.Write( buffer, 0, buffer.Length );
             * m_Stream.WriteByte( 0 );*/
        }
示例#5
0
        /// <summary>
        /// Writes a dynamic-length big-endian unicode string value to the underlying stream, followed by a 2-byte null character.
        /// </summary>
        public void WriteBigUniNull(string value)
        {
            if (value == null)
            {
                Console.WriteLine("Network: Attempted to WriteBigUniNull() with null value");
                value = string.Empty;
            }

            int length = value.Length;

            UnderlyingStream.SetLength(UnderlyingStream.Length + ((length + 1) * 2));

            UnderlyingStream.Position += Encoding.BigEndianUnicode.GetBytes(value, 0, length, UnderlyingStream.GetBuffer(), (int)UnderlyingStream.Position);
            UnderlyingStream.Position += 2;

            /*byte[] buffer = Encoding.BigEndianUnicode.GetBytes( value );
             *
             * m_Stream.Write( buffer, 0, buffer.Length );
             *
             * m_Buffer[0] = 0;
             * m_Buffer[1] = 0;
             * m_Stream.Write( m_Buffer, 0, 2 );*/
        }
示例#6
0
 public override void SetLength(long value)
 {
     UnderlyingStream.SetLength(value);
 }