コード例 #1
0
ファイル: MessageReader.cs プロジェクト: romkatv/iFix
 // Reads a single FIX messages and returns it. It shall contain
 // all fields, including header and trailer. No validation is
 // performed.
 //
 // This method is NOT thread-safe.
 //
 // Throws MessageTooLargeException if incoming message exceeds
 // MaxMessageSize. After that every call to ReadMessage() will throw
 // MessageTooLargeException.
 //
 // Throws EmptyStreamException if nothing can be read from the
 // underlying stream.
 public async Task<ArraySegment<byte>> ReadMessage(Stream strm)
 {
     Assert.True(strm != null);
     var trailerMatcher = new MessageTrailerMatcher();
     int messageEnd = trailerMatcher.FindTrailer(_buf, _startPos, _endPos);
     // Keep reading from the underlying stream until we find trailer.
     while (messageEnd == 0)
     {
         EnsureBufferSpace();
         Assert.True(_endPos < _buf.Length, "_endPos = {0}, _buf.Length = {1}", _endPos, _buf.Length);
         int read = await strm.ReadAsync(_buf, _endPos, _buf.Length - _endPos);
         if (read <= 0)
         {
             var partial = new ArraySegment<byte>(_buf, _startPos, _endPos - _startPos);
             throw new EmptyStreamException("Read so far: " + partial.AsAscii());
         }
         messageEnd = trailerMatcher.FindTrailer(_buf, _endPos, _endPos + read);
         _endPos += read;
     }
     var res = new ArraySegment<byte>(_buf, _startPos, messageEnd - _startPos);
     _startPos = messageEnd;
     if (_log.IsDebugEnabled) _log.Debug("IN: {0}", res.AsAscii());
     else _log.Info("IN: {0}", Truncate(res.AsAscii(), 1024));
     return res;
 }
コード例 #2
0
ファイル: MessageReader.cs プロジェクト: buybackoff/iFix
        // Reads a single FIX messages and returns it. It shall contain
        // all fields, including header and trailer. No validation is
        // performed.
        //
        // This method is NOT thread-safe.
        //
        // Throws MessageTooLargeException if incoming message exceeds
        // MaxMessageSize. After that every call to ReadMessage() will throw
        // MessageTooLargeException.
        //
        // Throws EmptyStreamException if nothing can be read from the
        // underlying stream.
        public async Task <ArraySegment <byte> > ReadMessage(Stream strm)
        {
            Assert.True(strm != null);
            var trailerMatcher = new MessageTrailerMatcher();
            int messageEnd     = trailerMatcher.FindTrailer(_buf, _startPos, _endPos);

            // Keep reading from the underlying stream until we find trailer.
            while (messageEnd == 0)
            {
                EnsureBufferSpace();
                Assert.True(_endPos < _buf.Length, "_endPos = {0}, _buf.Length = {1}", _endPos, _buf.Length);
                int read = await strm.ReadAsync(_buf, _endPos, _buf.Length - _endPos);

                if (read <= 0)
                {
                    var partial = new ArraySegment <byte>(_buf, _startPos, _endPos - _startPos);
                    throw new EmptyStreamException("Read so far: " + partial.AsAscii());
                }
                messageEnd = trailerMatcher.FindTrailer(_buf, _endPos, _endPos + read);
                _endPos   += read;
            }
            var res = new ArraySegment <byte>(_buf, _startPos, messageEnd - _startPos);

            _startPos = messageEnd;
            if (_log.IsDebugEnabled)
            {
                _log.Debug("IN: {0}", res.AsAscii());
            }
            else
            {
                _log.Info("IN: {0}", Truncate(res.AsAscii(), 1024));
            }
            return(res);
        }
コード例 #3
0
ファイル: Deserialization.cs プロジェクト: romkatv/iFix
 public static bool ParseBool(ArraySegment<byte> bytes)
 {
     if (bytes.Count == 1)
     {
         if (bytes.Array[bytes.Offset] == (byte)'Y')
             return true;
         if (bytes.Array[bytes.Offset] == (byte)'N')
             return false;
     }
     throw new MalformedMessageException(String.Format("Can't parse bool from {0}", bytes.AsAscii()));
 }
コード例 #4
0
ファイル: Deserialization.cs プロジェクト: romkatv/iFix
 public static long ParseLong(ArraySegment<byte> bytes)
 {
     // Parsing integers is a very common operation, so we want it to be fast.
     if (bytes.Count == 0)
         throw new MalformedMessageException("Can't parse long from empty byte sequence");
     int i = 0;
     int sign = 1;
     if (bytes.Array[bytes.Offset] == (byte)'-')
     {
         sign = -1;
         i = 1;
     }
     long abs = 0;
     for (; i != bytes.Count; ++i)
     {
         long digit = bytes.Array[bytes.Offset + i] - (byte)'0';
         if (digit < 0 || digit > 9)
             throw new MalformedMessageException(String.Format("Can't parse long from {0}", bytes.AsAscii()));
         abs *= 10;
         abs += digit;
     }
     return sign * abs;
 }
コード例 #5
0
ファイル: Deserialization.cs プロジェクト: buybackoff/iFix
 public static char ParseChar(ArraySegment <byte> bytes)
 {
     if (bytes.Count != 1)
     {
         throw new MalformedMessageException(String.Format("Can't parse char from {0}", bytes.AsAscii()));
     }
     return((char)bytes.Array[bytes.Offset]);
 }
コード例 #6
0
ファイル: Deserialization.cs プロジェクト: buybackoff/iFix
 public static bool ParseBool(ArraySegment <byte> bytes)
 {
     if (bytes.Count == 1)
     {
         if (bytes.Array[bytes.Offset] == (byte)'Y')
         {
             return(true);
         }
         if (bytes.Array[bytes.Offset] == (byte)'N')
         {
             return(false);
         }
     }
     throw new MalformedMessageException(String.Format("Can't parse bool from {0}", bytes.AsAscii()));
 }
コード例 #7
0
ファイル: Deserialization.cs プロジェクト: buybackoff/iFix
        public static long ParseLong(ArraySegment <byte> bytes)
        {
            // Parsing integers is a very common operation, so we want it to be fast.
            if (bytes.Count == 0)
            {
                throw new MalformedMessageException("Can't parse long from empty byte sequence");
            }
            int i    = 0;
            int sign = 1;

            if (bytes.Array[bytes.Offset] == (byte)'-')
            {
                sign = -1;
                i    = 1;
            }
            long abs = 0;

            for (; i != bytes.Count; ++i)
            {
                long digit = bytes.Array[bytes.Offset + i] - (byte)'0';
                if (digit < 0 || digit > 9)
                {
                    throw new MalformedMessageException(String.Format("Can't parse long from {0}", bytes.AsAscii()));
                }
                abs *= 10;
                abs += digit;
            }
            return(sign * abs);
        }
コード例 #8
0
ファイル: Deserialization.cs プロジェクト: buybackoff/iFix
        // Static methods ParseXXX() implement deserialization of FIX value types.
        // See http://www.onixs.biz/fix-dictionary/4.4/#DataTypes.

        public static string ParseString(ArraySegment <byte> bytes)
        {
            return(bytes.AsAscii());
        }
コード例 #9
0
ファイル: Deserialization.cs プロジェクト: romkatv/iFix
 // Static methods ParseXXX() implement deserialization of FIX value types.
 // See http://www.onixs.biz/fix-dictionary/4.4/#DataTypes.
 public static string ParseString(ArraySegment<byte> bytes)
 {
     return bytes.AsAscii();
 }
コード例 #10
0
ファイル: Deserialization.cs プロジェクト: romkatv/iFix
 public static char ParseChar(ArraySegment<byte> bytes)
 {
     if (bytes.Count != 1)
         throw new MalformedMessageException(String.Format("Can't parse char from {0}", bytes.AsAscii()));
     return (char)bytes.Array[bytes.Offset];
 }
コード例 #11
0
 public override string ToString()
 {
     return(_serialized.AsAscii());
 }
コード例 #12
0
 public override string ToString()
 {
     return(String.Format("{0}={1}", _tag.AsAscii(), _value.AsAscii()));
 }