|
1 | | -using System.Text; |
| 1 | +namespace System; |
2 | 2 |
|
3 | | -namespace System; |
4 | | - |
5 | | -internal static class UnitFormUtf8 |
| 3 | +internal static partial class UnitFormUtf8 |
6 | 4 | { |
7 | | - // General (default) form |
8 | | - internal static ReadOnlySpan<byte> General => new(InnerBytes.General); |
9 | | - |
10 | | - // Basic forms |
11 | | - internal static ReadOnlySpan<byte> Canonical => new(InnerBytes.Canonical); |
12 | | - internal static ReadOnlySpan<byte> JsonObj => new(InnerBytes.JsonObj); |
13 | | - internal static ReadOnlySpan<byte> Empty => new(InnerBytes.Empty); |
14 | | - |
15 | | - // Extended forms |
16 | | - internal static ReadOnlySpan<byte> CanonicalExtended => new(InnerBytes.CanonicalExtended); |
17 | | - internal static ReadOnlySpan<byte> JsonObjExtended => new(InnerBytes.JsonObjExtended); |
18 | | - internal static ReadOnlySpan<byte> EmptyExtended => new(InnerBytes.EmptyExtended); |
19 | | - |
20 | | - // We initialize the byte arrays inline with no static ctor to obtain and cache them |
21 | | - // lazily only on demand, and also isolate them in a nested class for thread-safety. |
22 | | - private static class InnerBytes |
23 | | - { |
24 | | - internal static readonly byte[] General = InnerGetBytes(UnitForm.General); |
25 | | - |
26 | | - internal static readonly byte[] Canonical = InnerGetBytes(UnitForm.Canonical); |
27 | | - internal static readonly byte[] JsonObj = InnerGetBytes(UnitForm.JsonObj); |
28 | | - internal static readonly byte[] Empty = InnerGetBytes(UnitForm.Empty); |
29 | | - |
30 | | - internal static readonly byte[] CanonicalExtended = InnerGetBytes(UnitForm.CanonicalExtended); |
31 | | - internal static readonly byte[] JsonObjExtended = InnerGetBytes(UnitForm.JsonObjExtended); |
32 | | - internal static readonly byte[] EmptyExtended = InnerGetBytes(UnitForm.EmptyExtended); |
33 | | - |
34 | | - // We use the most proven method to obtain UTF-8 bytes. |
35 | | - private static byte[] InnerGetBytes(string s) |
36 | | - => |
37 | | - Encoding.UTF8.GetBytes(s); |
38 | | - } |
39 | 5 | } |
0 commit comments