示例#1
0
        /// <summary>
        /// Writes the specified Unicode string to the buffer as a LFS encoded string.
        /// </summary>
        /// <param name="value">A Unicode string.</param>
        /// <param name="length">The maximum length of the string to write.</param>
        public void Write(string value, int length)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            LfsEncoding.GetBytes(value, buffer, position, length);
            position += length;
        }
示例#2
0
        /// <summary>
        /// Sends a message or command to LFS.
        /// </summary>
        /// <param name="message">The message to send.</param>
        /// <param name="args">Arguments to format the message with.</param>
        public void Send(string message, params object[] args)
        {
            const int    MsxLen        = 96;
            const int    MstLen        = 64;
            const string CommandPrefix = "/";

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            ThrowIfDisposed();
            ThrowIfNotConnected();

            message = String.Format(message, args);
            if (message.StartsWith(CommandPrefix, StringComparison.OrdinalIgnoreCase))
            {
                Send(new IS_MST {
                    Msg = message
                });                                 // Send command.
            }
            else
            {
                // Get the length the string will be once it's encoded.
                int length = LfsEncoding.GetByteCount(message, MsxLen);
                if (length < MstLen)
                {
                    Send(new IS_MST {
                        Msg = message
                    });                                 // Send normal message.
                }
                else
                {
                    Send(new IS_MSX {
                        Msg = message
                    });                                 // Send extended message.
                }
            }
        }
示例#3
0
 /// <summary>
 /// Reads a LFS encoded string from the buffer.
 /// </summary>
 /// <param name="count">The number of bytes to read.</param>
 /// <returns>A Unicode string.</returns>
 public string ReadString(int count)
 {
     position += count;
     return(LfsEncoding.GetString(buffer, position - count, count));
 }