Skip to content

Commit

Permalink
API defined
Browse files Browse the repository at this point in the history
As extension-method per #61 (comment)
  • Loading branch information
gfoidl committed Nov 9, 2019
1 parent b6b35f0 commit fce80dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
44 changes: 44 additions & 0 deletions source/gfoidl.Base64/Extensions/ReadOnlySequenceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Buffers;

namespace gfoidl.Base64
{
public static class ReadOnlySequenceExtensions
{
public static void Encode(this Base64? encoder, in ReadOnlySequence<byte> data, IBufferWriter<byte>? writer, out long consumed, out long written)
{
if (data.IsEmpty)
{
consumed = 0;
written = 0;
return;
}

if (encoder is null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.encoder);

if (writer is null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.writer);

throw new NotImplementedException();
}
//---------------------------------------------------------------------
public static bool TryDecode(this Base64? encoder, in ReadOnlySequence<byte> base64, IBufferWriter<byte>? writer, out long consumed, out long written)
{
if (base64.IsEmpty)
{
consumed = 0;
written = 0;
return true;
}

if (encoder == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.encoder);

if (writer is null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.writer);

throw new NotImplementedException();
}
}
}
10 changes: 9 additions & 1 deletion source/gfoidl.Base64/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static ThrowHelper()
s_resources = new Lazy<ResourceManager>(() => new ResourceManager($"{ns}.Strings", typeof(ThrowHelper).Assembly));
}
//---------------------------------------------------------------------
public static void ThrowArgumentNullException(ExceptionArgument argument) => throw GetArgumentNullException(argument);
public static void ThrowArgumentOutOfRangeException(ExceptionArgument argument) => throw GetArgumentOutOfRangeException(argument);
public static void ThrowMalformedInputException(int urlEncodedLen) => throw GetMalformdedInputException(urlEncodedLen);
public static void ThrowForOperationNotDone(OperationStatus status) => throw GetExceptionForOperationNotDone(status);
Expand All @@ -27,6 +28,11 @@ public static void ThrowArgumentOutOfRangeException(ExceptionArgument argument,
throw GetArgumentOutOfRangeException(argument, ressource);
}
//---------------------------------------------------------------------
private static Exception GetArgumentNullException(ExceptionArgument argument)
{
return new ArgumentNullException(GetArgumentName(argument));
}
//---------------------------------------------------------------------
private static Exception GetArgumentOutOfRangeException(ExceptionArgument argument)
{
return new ArgumentOutOfRangeException(GetArgumentName(argument));
Expand Down Expand Up @@ -75,8 +81,10 @@ private static string GetResource(ExceptionRessource ressource)
//-------------------------------------------------------------------------
internal enum ExceptionArgument
{
encoder,
encodedLength,
length,
encodedLength
writer
}
//---------------------------------------------------------------------
internal enum ExceptionRessource
Expand Down
9 changes: 8 additions & 1 deletion source/gfoidl.Base64/gfoidl.Base64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ For .NET Core 3.0 onwards encoding / decoding is done with SIMD-support.
<Compile Remove="**\*.netstandard.cs" />
<Compile Remove="**\*.sse.cs" />
<Compile Remove="**\*.avx.cs" />
<Compile Remove="Extensions\ReadOnlySequenceExtensions.cs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -64,9 +65,15 @@ For .NET Core 3.0 onwards encoding / decoding is done with SIMD-support.
<Compile Include="**\*.netcoreapp.cs" />
<Compile Include="**\*.sse.cs" />
<Compile Include="**\*.avx.cs" />
<Compile Include="Extensions\ReadOnlySequenceExtensions.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<Compile Include="**\*.netstandard.cs" />
<Compile Include="Extensions\ReadOnlySequenceExtensions.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<Compile Include="**\*.netstandard.cs" />
</ItemGroup>

Expand Down

0 comments on commit fce80dd

Please sign in to comment.