public void WriteLine(Utf8Span text, IBufferTransformation transformation = null) { int encoded = text.Bytes.Length; if (_symbols == SymbolTable.InvariantUtf8) { while (!text.Bytes.TryCopyTo(Free)) { Resize(); } } else { while (!_symbols.TryEncode(text.Bytes, Free, out var consumed, out encoded)) { Resize(); } } encoded += CopyBytesAt(encoded, Newline); if (transformation == null) { _written += encoded; return; } if (!TryApplyTransformation(transformation, encoded)) { Resize(); Write(text, transformation); } }
public void Write(string text, IBufferTransformation transformation = null) { int encoded = WriteCore(text); if (transformation == null) { _written += encoded; return; } if (!TryApplyTransformation(transformation, encoded)) { Resize(); Write(text, transformation); } }
private bool TryApplyTransformation(IBufferTransformation transformation, int dataLength) { Debug.Assert(transformation != null); var status = transformation.Transform(Buffer.Slice(Index), dataLength, out dataLength); if (status == OperationStatus.Done) { _written += dataLength; return(true); } if (status == OperationStatus.InvalidData || status == OperationStatus.NeedMoreData) { throw new Exception("invalid value or transformation"); } return(true); }
public void WriteText <T>(T value, ParsedFormat format = default, IBufferTransformation transformation = null) where T : IBufferFormattable { int written; while (!value.TryFormat(Free, out written, format, _symbols)) { Resize(); } if (transformation == null) { _written += written; return; } if (!TryApplyTransformation(transformation, written)) { Resize(); WriteText(value, format, transformation); } }
public void WriteBytes <T>(T value, ParsedFormat format = default, IBufferTransformation transformation = null) where T : IWritable { int written; while (!value.TryWrite(Free, out written, format)) { Resize(); } if (transformation == null) { _written += written; return; } if (!TryApplyTransformation(transformation, written)) { Resize(); WriteBytes(value, format, transformation); } }
public TransformationFormat(params IBufferTransformation[] transformations) { _format = default; _first = null; _rest = transformations; }
public TransformationFormat(IBufferTransformation transformation) { _format = default; _first = transformation; _rest = null; }
public void WriteLine(Utf8String text, IBufferTransformation transformation = null) { WriteLine((Utf8Span)text, transformation); }