Target .NET Standard 2.1, .NET 6, .NET 8 only (#8184)

* Target .NET Standard 2.1, .NET 6, .NET 8 only

* Remove mono usage

* Fix bat name ref

* Up deps

* Up deps

* Reinstate build-windows

* Fix name

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Björn Harrtell
2023-12-19 23:43:55 +01:00
committed by GitHub
parent e5fc3b16d8
commit 129ef422e8
15 changed files with 109 additions and 449 deletions

View File

@@ -43,11 +43,11 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
using System.Buffers.Binary;
#endif
#if ENABLE_SPAN_T && !UNSAFE_BYTEBUFFER && !NETSTANDARD2_1
#if ENABLE_SPAN_T && !UNSAFE_BYTEBUFFER
#warning ENABLE_SPAN_T requires UNSAFE_BYTEBUFFER to also be defined
#endif
@@ -55,7 +55,7 @@ namespace Google.FlatBuffers
{
public abstract class ByteBufferAllocator
{
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public abstract Span<byte> Span { get; }
public abstract ReadOnlySpan<byte> ReadOnlySpan { get; }
public abstract Memory<byte> Memory { get; }
@@ -103,7 +103,7 @@ namespace Google.FlatBuffers
InitBuffer();
}
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public override Span<byte> Span => _buffer;
public override ReadOnlySpan<byte> ReadOnlySpan => _buffer;
public override Memory<byte> Memory => _buffer;
@@ -237,7 +237,7 @@ namespace Google.FlatBuffers
return SizeOf<T>() * x.Count;
}
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public static int ArraySize<T>(Span<T> x)
{
return SizeOf<T>() * x.Length;
@@ -246,7 +246,7 @@ namespace Google.FlatBuffers
// Get a portion of the buffer casted into an array of type T, given
// the buffer position and length.
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public T[] ToArray<T>(int pos, int len)
where T : struct
{
@@ -274,7 +274,7 @@ namespace Google.FlatBuffers
return ToArray<byte>(0, Length);
}
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public ReadOnlyMemory<byte> ToReadOnlyMemory(int pos, int len)
{
return _buffer.ReadOnlyMemory.Slice(pos, len);
@@ -337,7 +337,7 @@ namespace Google.FlatBuffers
((input & 0xFF00000000000000UL) >> 56));
}
#if !UNSAFE_BYTEBUFFER && (!ENABLE_SPAN_T || !NETSTANDARD2_1)
#if !UNSAFE_BYTEBUFFER && !ENABLE_SPAN_T
// Helper functions for the safe (but slower) version.
protected void WriteLittleEndian(int offset, int count, ulong data)
{
@@ -377,7 +377,7 @@ namespace Google.FlatBuffers
}
return r;
}
#elif ENABLE_SPAN_T && NETSTANDARD2_1
#elif ENABLE_SPAN_T
protected void WriteLittleEndian(int offset, int count, ulong data)
{
if (BitConverter.IsLittleEndian)
@@ -427,7 +427,7 @@ namespace Google.FlatBuffers
#endif
}
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public void PutSbyte(int offset, sbyte value)
{
@@ -487,7 +487,7 @@ namespace Google.FlatBuffers
}
}
}
#elif ENABLE_SPAN_T && NETSTANDARD2_1
#elif ENABLE_SPAN_T
public void PutStringUTF8(int offset, string value)
{
AssertOffsetAndLength(offset, value.Length);
@@ -652,7 +652,7 @@ namespace Google.FlatBuffers
// that contains it.
ConversionUnion union;
union.intValue = 0;
union.floatValue = value;
union.floatValue = value;
WriteLittleEndian(offset, sizeof(float), (ulong)union.intValue);
}
@@ -664,7 +664,7 @@ namespace Google.FlatBuffers
#endif // UNSAFE_BYTEBUFFER
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public sbyte GetSbyte(int index)
{
AssertOffsetAndLength(index, sizeof(sbyte));
@@ -698,7 +698,7 @@ namespace Google.FlatBuffers
return Encoding.UTF8.GetString(buffer, len);
}
}
#elif ENABLE_SPAN_T && NETSTANDARD2_1
#elif ENABLE_SPAN_T
public string GetStringUTF8(int startPos, int len)
{
return Encoding.UTF8.GetString(_buffer.Span.Slice(startPos, len));
@@ -765,7 +765,7 @@ namespace Google.FlatBuffers
#if ENABLE_SPAN_T // && UNSAFE_BYTEBUFFER
ReadOnlySpan<byte> span = _buffer.ReadOnlySpan.Slice(offset);
return BinaryPrimitives.ReadUInt64LittleEndian(span);
#else
#else
fixed (byte* ptr = _buffer.Buffer)
{
return BitConverter.IsLittleEndian
@@ -885,16 +885,16 @@ namespace Google.FlatBuffers
}
/// <summary>
/// Copies an array segment of type T into this buffer, ending at the
/// given offset into this buffer. The starting offset is calculated
/// Copies an array segment of type T into this buffer, ending at the
/// given offset into this buffer. The starting offset is calculated
/// based on the count of the array segment and is the value returned.
/// </summary>
/// <typeparam name="T">The type of the input data (must be a struct)
/// </typeparam>
/// <param name="offset">The offset into this buffer where the copy
/// <param name="offset">The offset into this buffer where the copy
/// will end</param>
/// <param name="x">The array segment to copy data from</param>
/// <returns>The 'start' location of this buffer now, after the copy
/// <returns>The 'start' location of this buffer now, after the copy
/// completed</returns>
public int Put<T>(int offset, ArraySegment<T> x)
where T : struct
@@ -921,7 +921,7 @@ namespace Google.FlatBuffers
offset -= numBytes;
AssertOffsetAndLength(offset, numBytes);
// if we are LE, just do a block copy
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
MemoryMarshal.Cast<T, byte>(x).CopyTo(_buffer.Span.Slice(offset, numBytes));
#else
var srcOffset = ByteBuffer.SizeOf<T>() * x.Offset;
@@ -942,17 +942,17 @@ namespace Google.FlatBuffers
}
/// <summary>
/// Copies an array segment of type T into this buffer, ending at the
/// given offset into this buffer. The starting offset is calculated
/// Copies an array segment of type T into this buffer, ending at the
/// given offset into this buffer. The starting offset is calculated
/// based on the count of the array segment and is the value returned.
/// </summary>
/// <typeparam name="T">The type of the input data (must be a struct)
/// </typeparam>
/// <param name="offset">The offset into this buffer where the copy
/// <param name="offset">The offset into this buffer where the copy
/// will end</param>
/// <param name="ptr">The pointer to copy data from</param>
/// <param name="sizeInBytes">The number of bytes to copy</param>
/// <returns>The 'start' location of this buffer now, after the copy
/// <returns>The 'start' location of this buffer now, after the copy
/// completed</returns>
public int Put<T>(int offset, IntPtr ptr, int sizeInBytes)
where T : struct
@@ -980,7 +980,7 @@ namespace Google.FlatBuffers
// if we are LE, just do a block copy
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
unsafe
{
{
var span = new Span<byte>(ptr.ToPointer(), sizeInBytes);
span.CopyTo(_buffer.Span.Slice(offset, sizeInBytes));
}
@@ -1001,7 +1001,7 @@ namespace Google.FlatBuffers
return offset;
}
#if ENABLE_SPAN_T && (UNSAFE_BYTEBUFFER || NETSTANDARD2_1)
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
public int Put<T>(int offset, Span<T> x)
where T : struct
{