public static void WriteLittleEndian <[Primitive] T>(this WritableBuffer buffer, T value) where T : struct { int len = Unsafe.SizeOf <T>(); buffer.Ensure(len); buffer.Buffer.Span.WriteLittleEndian(value); buffer.Advance(len); }
/// <summary> /// Writes the source <see cref="Span{Byte}"/> to the <see cref="WritableBuffer"/>. /// </summary> /// <param name="buffer">The <see cref="WritableBuffer"/></param> /// <param name="source">The <see cref="Span{Byte}"/> to write</param> public static void Write(this WritableBuffer buffer, ReadOnlySpan <byte> source) { if (buffer.Buffer.IsEmpty) { buffer.Ensure(); } // Fast path, try copying to the available memory directly if (source.Length <= buffer.Buffer.Length) { source.CopyTo(buffer.Buffer.Span); buffer.Advance(source.Length); return; } var remaining = source.Length; var offset = 0; while (remaining > 0) { var writable = Math.Min(remaining, buffer.Buffer.Length); buffer.Ensure(writable); if (writable == 0) { continue; } source.Slice(offset, writable).CopyTo(buffer.Buffer.Span); remaining -= writable; offset += writable; buffer.Advance(writable); } }
public void Advance(int count) { _span = _span.Slice(count); _writableBuffer.Advance(count); }
public void Advance(int bytes) { _writer.Advance(bytes); }