private static R <T> ParseKeyValueLine <T>(T qm, string line) where T : IQueryMessage { if (string.IsNullOrWhiteSpace(line)) { return(R <T> .Err("Empty")); } var ss = new SpanSplitter(); var lineSpan = ss.First(line, ' '); var key = default(ReadOnlySpan <char>); var value = default(ReadOnlySpan <char>); try { do { var param = ss.Trim(lineSpan); var kvpSplitIndex = param.IndexOf('='); var skey = kvpSplitIndex >= 0 ? param.Slice(0, kvpSplitIndex) : ReadOnlySpan <char> .Empty; value = kvpSplitIndex <= param.Length - 1 ? param.Slice(kvpSplitIndex + 1) : ReadOnlySpan <char> .Empty; qm.SetField(skey.NewString(), value); if (!ss.HasNext) { break; } lineSpan = ss.Next(lineSpan); } while (lineSpan.Length > 0); return(R <T> .OkR(qm)); } catch (Exception ex) { OnError?.Invoke(null, new Error(qm.GetType().Name, line, key.NewString(), value.NewString(), ex)); } return(R <T> .Err("Error")); }
private bool ParseKeyValueLine(IMessage qm, ReadOnlySpan <byte> line, HashSet <string> indexing, List <string> single) { if (line.IsEmpty) { return(true); } var ss = new SpanSplitter <byte>(); ss.First(line, AsciiSpace); var key = ReadOnlySpan <byte> .Empty; var value = ReadOnlySpan <byte> .Empty; try { do { var param = ss.Trim(line); var kvpSplitIndex = param.IndexOf(AsciiEquals); key = kvpSplitIndex >= 0 ? param.Slice(0, kvpSplitIndex) : ReadOnlySpan <byte> .Empty; value = kvpSplitIndex <= param.Length - 1 ? param.Slice(kvpSplitIndex + 1) : ReadOnlySpan <byte> .Empty; if (!key.IsEmpty) { var keyStr = key.NewUtf8String(); qm.SetField(keyStr, value, this); if (indexing != null) { if (single is null) { indexing.Add(keyStr); } else if (!indexing.Contains(keyStr)) { single.Add(keyStr); } else { indexing = null; single = null; } } } if (!ss.HasNext) { break; } line = ss.Next(line); } while (line.Length > 0); return(true); } catch (Exception ex) { Log.Error(ex, "Deserialization format error. Data: class:{0} field:{1} value:{2} msg:{3}", qm.GetType().Name, key.NewUtf8String(), value.NewUtf8String(), line.NewUtf8String()); return(false); } }
private static bool ParseKeyValueLine(IMessage qm, ReadOnlySpan <byte> line, HashSet <string> indexing, List <string> single) { if (line.IsEmpty) { return(true); } var ss = new SpanSplitter <byte>(); ss.First(line, AsciiSpace); var key = ReadOnlySpan <byte> .Empty; var value = ReadOnlySpan <byte> .Empty; try { do { var param = ss.Trim(line); var kvpSplitIndex = param.IndexOf(AsciiEquals); key = kvpSplitIndex >= 0 ? param.Slice(0, kvpSplitIndex) : ReadOnlySpan <byte> .Empty; value = kvpSplitIndex <= param.Length - 1 ? param.Slice(kvpSplitIndex + 1) : ReadOnlySpan <byte> .Empty; if (!key.IsEmpty) { var keyStr = key.NewUtf8String(); qm.SetField(keyStr, value); if (indexing != null) { if (single == null) { indexing.Add(keyStr); } else if (!indexing.Contains(keyStr)) { single.Add(keyStr); } else { indexing = null; single = null; } } } if (!ss.HasNext) { break; } line = ss.Next(line); } while (line.Length > 0); return(true); } catch (Exception ex) { OnError?.Invoke(null, new Error(qm.GetType().Name, line.NewUtf8String(), key.NewUtf8String(), value.NewUtf8String(), ex)); } return(false); }