Adds more packets (#177)
This commit is contained in:
parent
c0805850c1
commit
5052bf9af3
15 changed files with 609 additions and 109 deletions
|
|
@ -136,7 +136,10 @@ namespace System.Buffers
|
|||
{
|
||||
int length = value.Length;
|
||||
pos += Encoding.ASCII.GetBytes(value.AsSpan(0, length), span.Slice(pos, length));
|
||||
span[pos++] = 0; // Null terminator
|
||||
#if NO_LOCAL_INIT
|
||||
span[pos] = 0; // Null terminator
|
||||
#endif
|
||||
pos++;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
@ -145,7 +148,10 @@ namespace System.Buffers
|
|||
var length = value.Length < max ? value.Length : max - 1;
|
||||
|
||||
pos += Encoding.ASCII.GetBytes(value.AsSpan(0, length), span.Slice(pos, length));
|
||||
span[pos++] = 0; // Null terminator
|
||||
#if NO_LOCAL_INIT
|
||||
span[pos] = 0; // Null terminator
|
||||
#endif
|
||||
pos++;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
@ -164,22 +170,6 @@ namespace System.Buffers
|
|||
pos += amount;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteAsciiFixedNull(this Span<byte> span, ref int pos, string value, int amount)
|
||||
{
|
||||
var length = value.Length < amount ? value.Length : amount - 1;
|
||||
#if NO_LOCAL_INIT
|
||||
int bytesWritten = Encoding.ASCII.GetBytes(value.AsSpan(0, amount), span.Slice(pos, amount));
|
||||
|
||||
if (bytesWritten < amount)
|
||||
span.Slice(pos + bytesWritten, amount - bytesWritten).Clear();
|
||||
#else
|
||||
Encoding.ASCII.GetBytes(value.AsSpan(0, length), span.Slice(pos, length));
|
||||
#endif
|
||||
|
||||
pos += amount;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteBigUni(this Span<byte> span, ref int pos, string value)
|
||||
{
|
||||
|
|
@ -191,5 +181,34 @@ namespace System.Buffers
|
|||
{
|
||||
pos += Encoding.Unicode.GetBytes(value, span.Slice(pos));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteBigUniNull(this Span<byte> span, ref int pos, string value)
|
||||
{
|
||||
pos += Encoding.BigEndianUnicode.GetBytes(value, span.Slice(pos));
|
||||
#if NO_LOCAL_INIT
|
||||
BinaryPrimitives.WriteUInt16BigEndian(span.Slice(pos, 2), 0); // Null terminator
|
||||
#endif
|
||||
pos += 2;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void WriteLittleUniNull(this Span<byte> span, ref int pos, string value)
|
||||
{
|
||||
pos += Encoding.Unicode.GetBytes(value, span.Slice(pos));
|
||||
#if NO_LOCAL_INIT
|
||||
BinaryPrimitives.WriteUInt16BigEndian(span.Slice(pos, 2), 0); // Null terminator
|
||||
#endif
|
||||
pos += 2;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Write(this Span<byte> span, ref int pos, Point3D p)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt16BigEndian(span.Slice(pos, 2), (ushort)p.X);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(span.Slice(pos + 2, 2), (ushort)p.Y);
|
||||
span[pos + 4] = (byte)p.Z;
|
||||
pos += 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue