public static void WriteMessage(EventPipeMessage message, PipeWriter writer) { var json = new JObject( new JProperty("type", message.Type), new JProperty("payload", JObject.FromObject(message))); var str = json.ToString(Formatting.None); var bytes = Encoding.UTF8.GetBytes(str); writer.Write(bytes.AsSpan()); writer.Write(RecordSeparatorMemory.Span); }
public static bool TryParseMessage(ref ReadOnlySequence <byte> input, out EventPipeMessage message) { if (input.PositionOf(RecordSeparator) is SequencePosition position) { ReadOnlySequence <byte> buffer = input.Slice(input.Start, position); input = input.Slice(input.GetPosition(1, position)); message = ParseMessage(buffer); return(true); } else { message = null; return(false); } }