Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8eb8e1a

Browse files
committed
Add MemoryProvider ToMemoryStream(ROS<byte>) API
1 parent cc03cd3 commit 8eb8e1a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/ServiceStack.Text/DefaultMemory.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ public override int FromUtf8(ReadOnlySpan<byte> source, Span<char> destination)
559559
public override byte[] ToUtf8Bytes(ReadOnlySpan<char> source) => Encoding.UTF8.GetBytes(source.ToArray());
560560

561561
public override string FromUtf8Bytes(ReadOnlySpan<byte> source) => Encoding.UTF8.GetString(source.ToArray());
562+
563+
public override MemoryStream ToMemoryStream(ReadOnlySpan<byte> source) =>
564+
MemoryStreamFactory.GetStream(source.ToArray());
562565

563566
private static Guid ParseGeneralStyleGuid(ReadOnlySpan<char> value, out int len)
564567
{
@@ -567,7 +570,7 @@ private static Guid ParseGeneralStyleGuid(ReadOnlySpan<char> value, out int len)
567570

568571
int dash = 0;
569572
len = 32;
570-
bool hasParentesis = false;
573+
bool hasParenthesis = false;
571574

572575
if (value.Length < len)
573576
throw new FormatException(BadFormat);
@@ -577,7 +580,7 @@ private static Guid ParseGeneralStyleGuid(ReadOnlySpan<char> value, out int len)
577580
{
578581
n++;
579582
len += 2;
580-
hasParentesis = true;
583+
hasParenthesis = true;
581584

582585
if (buf[8 + n] != '-')
583586
throw new FormatException(BadFormat);
@@ -597,7 +600,7 @@ private static Guid ParseGeneralStyleGuid(ReadOnlySpan<char> value, out int len)
597600
if (value.Length < len)
598601
throw new FormatException(BadFormat);
599602

600-
if (hasParentesis)
603+
if (hasParenthesis)
601604
{
602605
var ce = buf[len - 1];
603606

src/ServiceStack.Text/MemoryProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ public abstract Task<object> DeserializeAsync(Stream stream, Type type,
6969

7070
public abstract byte[] ToUtf8Bytes(ReadOnlySpan<char> source);
7171
public abstract string FromUtf8Bytes(ReadOnlySpan<byte> source);
72+
public abstract MemoryStream ToMemoryStream(ReadOnlySpan<byte> source);
7273
}
7374
}

src/ServiceStack.Text/NetCoreMemory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ public override ReadOnlyMemory<char> FromUtf8(ReadOnlySpan<byte> source)
189189
public override byte[] ToUtf8Bytes(ReadOnlySpan<char> source) => ToUtf8(source).ToArray();
190190

191191
public override string FromUtf8Bytes(ReadOnlySpan<byte> source) => FromUtf8(source).ToString();
192+
public override MemoryStream ToMemoryStream(ReadOnlySpan<byte> source)
193+
{
194+
var ms = MemoryStreamFactory.GetStream(source.Length);
195+
ms.Write(source);
196+
return ms;
197+
}
192198
}
193199
}
194200

0 commit comments

Comments
 (0)