Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ufcpp committed Jun 10, 2020
1 parent df73da4 commit 3ea5cb9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions readme.md
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/)

0 comments on commit 3ea5cb9

Please sign in to comment.