예제 #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
        /// <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 );*/
        }
예제 #3
0
        /// <summary>
        /// Writes a dynamic-length little-endian unicode string value to the underlying stream, followed by a 2-byte null character.
        /// </summary>
        public void WriteLittleUniNull(string value)
        {
            if (value == null)
            {
                Console.WriteLine("Network: Attempted to WriteLittleUniNull() with null value");
                value = string.Empty;
            }

            int length = value.Length;

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

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

            /*byte[] buffer = Encoding.Unicode.GetBytes( value );
             *
             * m_Stream.Write( buffer, 0, buffer.Length );
             *
             * m_Buffer[0] = 0;
             * m_Buffer[1] = 0;
             * m_Stream.Write( m_Buffer, 0, 2 );*/
        }