-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# C# StringLiteralGenerator | ||
|
||
A C# [Source Generator](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.md) for optimizing UTF-8 binaries. | ||
|
||
Original source (mamual written): | ||
|
||
```cs | ||
namespace Sample | ||
{ | ||
partial class Literals | ||
{ | ||
[StringLiteral.Utf8Attribute("aαあ😊")] | ||
public static partial System.ReadOnlySpan<byte> S(); | ||
} | ||
} | ||
``` | ||
|
||
Generated source: | ||
|
||
```cs | ||
namespace Sample | ||
{ | ||
partial class Literals | ||
{ | ||
public static partial System.ReadOnlySpan<byte> S() => new byte[] {97, 206, 177, 227, 129, 130, 240, 159, 152, 138, }; | ||
} | ||
} | ||
``` | ||
|
||
- Generates UTF-8 binary data from string literals (UTF-16). | ||
- The UTF-8 data is optimized to avoid allocation. see: [C# ReadOnlySpan and static data](https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static/) |