public void WriteBytes <T>(T value, TransformationFormat format) where T : IWritable { while (!TryWriteBytes(value, format)) { Resize(); } }
public void Write <T>(T value, TransformationFormat format) where T : IBufferFormattable { while (!TryWrite(value, format)) { Resize(); } }
public void WriteLine(string text, TransformationFormat format) { while (!TryWriteLine(text, format)) { Resize(); } }
public void WriteLine(Utf8Span text, TransformationFormat transformation) { while (!TryWriteLine(text, transformation)) { Resize(); } }
public void BufferWriterTransform() { byte[] buffer = new byte[10]; var writer = BufferWriter.Create(buffer.AsSpan()); var transformation = new TransformationFormat(new RemoveTransformation(2)); ReadOnlyMemory <byte> value = new byte[] { 1, 2, 3 }; writer.WriteBytes(value, transformation); Assert.Equal(-1, buffer.AsSpan().IndexOf((byte)2)); }
public bool TryWriteLine(string text, TransformationFormat format) { if (!TryWriteLine(text, out int written)) { return(false); } if (!format.TryTransform(Free, ref written)) { return(false); } _written += written; return(true); }
public void WriteInt32Transformed() { TransformationFormat widen = new TransformationFormat(new AsciiToUtf16()); _sink.Reset(); var writer = BufferWriter.Create(_sink); writer.Write(255, widen); writer.Flush(); var result = _sink.ToStringAssumingUtf16Buffer(); Assert.Equal("255", result); }
public bool TryWrite <T>(T value, TransformationFormat format) where T : IBufferFormattable { if (!value.TryFormat(Free, out int written, format.Format, SymbolTable.InvariantUtf8)) { return(false); } if (format.TryTransform(Free, ref written)) { _written += written; return(true); } return(false); }
public bool TryWriteBytes <T>(T value, TransformationFormat format) where T : IWritable { if (!value.TryWrite(Free, out int written, format.Format)) { return(false); } if (format.TryTransform(Free, ref written)) { _written += written; return(true); } return(false); }
public bool TryWrite(Utf8Span text, TransformationFormat format) { int written = text.Bytes.Length; if (!text.Bytes.TryCopyTo(Free)) { return(false); } if (!format.TryTransform(Free, ref written)) { return(false); } _written += written; return(true); }
public void Write(Utf8String text, TransformationFormat transformation) => Write((Utf8Span)text, transformation);
public bool TryWrite(Utf8String text, TransformationFormat transformation) => TryWrite((Utf8Span)text, transformation);