示例#1
0
        private Boolean CanHandle(ReadOnlySequence <Byte> payload, NmeaMessage parser)
        {
            try
            {
                if (parser.CanHandle(payload))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"{parser.GetType().Name}.CanHandle({payload.ToString(Encoding.UTF8)}) generated the following exception:");
            }

            return(false);
        }
示例#2
0
        private Boolean ParseSentence(ReadOnlySequence <Byte> payload, out NmeaMessage message)
        {
            message = default;

            LineCount++;
            BytesRead += payload.Length;

            foreach (var parser in _parsers)
            {
                if (CanHandle(payload, parser))
                {
                    if (_logger.IsEnabled(LogLevel.Trace))
                    {
                        _logger.LogTrace($"Parsing Line {LineCount} with {parser.GetType().Name}: {payload.ToString(Encoding.UTF8)}");
                    }
                    try
                    {
                        message = parser.Parse(payload);
                        _unparsedSequenceLength = 0;
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, $"Line {LineCount} caused {parser.GetType().Name}.Parse({payload.ToString(Encoding.UTF8)}) to generate the following exception:");
                    }

                    break;
                }
            }

            if (_logger.IsEnabled(LogLevel.Trace))
            {
                _logger.LogTrace($"No parser found for Line {LineCount}: {payload.ToString(Encoding.UTF8)}");
            }

            _unparsedSequenceLength++;
            return(false);
        }