generated from OoLunar/DSharpPlus.Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use DI more correctly; New Raw HyperSerializerDelegate, intending for…
… passing byte arrays as responses; HyperStatus now includes the hyper serializer to use
- Loading branch information
Showing
80 changed files
with
2,937 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Toolkit.HighPerformance; | ||
|
||
namespace HyperSharp.Protocol | ||
{ | ||
/// <summary> | ||
/// Holds a collection of static methods implementing <see cref="HyperSerializerDelegate"/> for the most common of Content-Types. | ||
/// </summary> | ||
public static partial class HyperSerializers | ||
{ | ||
private static readonly byte[] _contentLengthHeader = "Content-Length: "u8.ToArray(); | ||
|
||
/// <summary> | ||
/// Serializes the body to the client as plain text using the <see cref="object.ToString"/> method with the <see cref="Encoding.UTF8"/> encoding. | ||
/// </summary> | ||
/// <inheritdoc cref="HyperSerializerDelegate"/> | ||
public static ValueTask<bool> RawAsync(HyperContext context, HyperStatus status, CancellationToken cancellationToken = default) | ||
{ | ||
ArgumentNullException.ThrowIfNull(context); | ||
ArgumentNullException.ThrowIfNull(status); | ||
|
||
byte[] body = status.Body as byte[] ?? Encoding.UTF8.GetBytes(status.Body?.ToString() ?? ""); | ||
int bodyLength = body.Length; | ||
|
||
// Write Content-Length header | ||
context.Connection.StreamWriter.Write<byte>(_contentLengthHeader); | ||
context.Connection.StreamWriter.Write<byte>(Encoding.UTF8.GetBytes(bodyLength.ToString(CultureInfo.InvariantCulture))); | ||
context.Connection.StreamWriter.Write<byte>(_newLine); | ||
|
||
// Write body | ||
context.Connection.StreamWriter.Write<byte>(_newLine); | ||
context.Connection.StreamWriter.Write<byte>(body); | ||
|
||
return ValueTask.FromResult(true); | ||
} | ||
} | ||
} |
47 changes: 42 additions & 5 deletions
47
src/HyperSharp/Protocol/HyperStatus/HyperStatus.Accepted.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
// <auto-generated/> | ||
// Last modified at 2024-06-28. | ||
// Last modified at 2024-07-30. | ||
|
||
#nullable enable | ||
namespace HyperSharp.Protocol | ||
{ | ||
public readonly partial record struct HyperStatus | ||
{ | ||
/// <inheritdoc cref="global::System.Net.HttpStatusCode.Accepted" /> | ||
public static HyperStatus Accepted() => new(global::System.Net.HttpStatusCode.Accepted, new HyperHeaderCollection(), null); | ||
public static HyperStatus Accepted() => new HyperStatus() | ||
{ | ||
Code = global::System.Net.HttpStatusCode.Accepted | ||
}; | ||
|
||
/// <inheritdoc cref="global::System.Net.HttpStatusCode.Accepted" /> | ||
/// <param name="body">The body of the response.</param> | ||
public static HyperStatus Accepted(object? body) => new(global::System.Net.HttpStatusCode.Accepted, new HyperHeaderCollection(), body); | ||
public static HyperStatus Accepted(object? body) => new HyperStatus() | ||
{ | ||
Code = global::System.Net.HttpStatusCode.Accepted, | ||
Body = body | ||
}; | ||
|
||
/// <inheritdoc cref="global::System.Net.HttpStatusCode.Accepted" /> | ||
/// <param name="body">The body of the response.</param> | ||
/// <param name="serializer">Which serializer to use to serialize the body.</param> | ||
public static HyperStatus Accepted(object? body, HyperSerializerDelegate serializer) => new HyperStatus() | ||
{ | ||
Code = global::System.Net.HttpStatusCode.Accepted, | ||
Body = body, | ||
Serializer = serializer | ||
}; | ||
|
||
/// <inheritdoc cref="global::System.Net.HttpStatusCode.Accepted" /> | ||
/// <param name="headers">The headers of the response.</param> | ||
public static HyperStatus Accepted(HyperHeaderCollection headers) => new(global::System.Net.HttpStatusCode.Accepted, headers, null); | ||
public static HyperStatus Accepted(HyperHeaderCollection headers) => new HyperStatus() | ||
{ | ||
Code = global::System.Net.HttpStatusCode.Accepted, | ||
Headers = headers | ||
}; | ||
|
||
/// <inheritdoc cref="global::System.Net.HttpStatusCode.Accepted" /> | ||
/// <param name="headers">The headers of the response.</param> | ||
/// <param name="body">The body of the response.</param> | ||
public static HyperStatus Accepted(HyperHeaderCollection headers, object? body) => new HyperStatus() | ||
{ | ||
Code = global::System.Net.HttpStatusCode.Accepted, | ||
Headers = headers, | ||
Body = body | ||
}; | ||
|
||
/// <inheritdoc cref="global::System.Net.HttpStatusCode.Accepted" /> | ||
/// <param name="headers">The headers of the response.</param> | ||
/// <param name="body">The body of the response.</param> | ||
public static HyperStatus Accepted(HyperHeaderCollection headers, object? body) => new(global::System.Net.HttpStatusCode.Accepted, headers, body); | ||
public static HyperStatus Accepted(HyperHeaderCollection headers, object? body, HyperSerializerDelegate serializer) => new HyperStatus() | ||
{ | ||
Code = global::System.Net.HttpStatusCode.Accepted, | ||
Headers = headers, | ||
Body = body, | ||
Serializer = serializer | ||
}; | ||
} | ||
} |
Oops, something went wrong.