// 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; }
// 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); }
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())); }
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; }
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]); }
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())); }
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); }
// 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()); }
// 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(); }
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]; }
public override string ToString() { return(_serialized.AsAscii()); }
public override string ToString() { return(String.Format("{0}={1}", _tag.AsAscii(), _value.AsAscii())); }