|
8 | 8 | using System.IO;
|
9 | 9 | using System.Threading.Tasks;
|
10 | 10 |
|
11 |
| -namespace SimpleBase |
| 11 | +namespace SimpleBase; |
| 12 | + |
| 13 | +/// <summary> |
| 14 | +/// Base16 encoding/decoding. |
| 15 | +/// </summary> |
| 16 | +public sealed class Base16 : IBaseCoder, IBaseStreamCoder, INonAllocatingBaseCoder |
12 | 17 | {
|
13 |
| - /// <summary> |
14 |
| - /// Base16 encoding/decoding. |
15 |
| - /// </summary> |
16 |
| - public sealed class Base16 : IBaseEncoder, IBaseStreamEncoder, INonAllocatingBaseEncoder |
17 |
| - { |
18 |
| - private static readonly Lazy<Base16> upperCase = new (() => new Base16(Base16Alphabet.UpperCase)); |
19 |
| - private static readonly Lazy<Base16> lowerCase = new (() => new Base16(Base16Alphabet.LowerCase)); |
20 |
| - private static readonly Lazy<Base16> modHex = new (() => new Base16(Base16Alphabet.ModHex)); |
| 18 | + private static readonly Lazy<Base16> upperCase = new (() => new Base16(Base16Alphabet.UpperCase)); |
| 19 | + private static readonly Lazy<Base16> lowerCase = new (() => new Base16(Base16Alphabet.LowerCase)); |
| 20 | + private static readonly Lazy<Base16> modHex = new (() => new Base16(Base16Alphabet.ModHex)); |
21 | 21 |
|
22 | 22 | /// <summary>
|
23 | 23 | /// Initializes a new instance of the <see cref="Base16"/> class.
|
@@ -78,83 +78,15 @@ public int GetSafeCharCountForEncoding(ReadOnlySpan<byte> buffer)
|
78 | 78 | return buffer.Length * 2;
|
79 | 79 | }
|
80 | 80 |
|
81 |
| - /// <summary> |
82 |
| - /// Encode to Base16 representation using uppercase lettering. |
83 |
| - /// </summary> |
84 |
| - /// <param name="bytes">Bytes to encode.</param> |
85 |
| - /// <returns>Base16 string.</returns> |
86 |
| - [Obsolete("Deprecated. Use Base16.UpperCase.Encode() instead")] |
87 |
| - public static unsafe string EncodeUpper(ReadOnlySpan<byte> bytes) |
88 |
| - { |
89 |
| - return UpperCase.Encode(bytes); |
90 |
| - } |
91 |
| - |
92 |
| - /// <summary> |
93 |
| - /// Encode to Base16 representation using lowercase lettering. |
94 |
| - /// </summary> |
95 |
| - /// <param name="bytes">Bytes to encode.</param> |
96 |
| - /// <returns>Base16 string.</returns> |
97 |
| - [Obsolete("Deprecated. Use Base16.LowerCase.Encode() instead")] |
98 |
| - public static unsafe string EncodeLower(ReadOnlySpan<byte> bytes) |
99 |
| - { |
100 |
| - return LowerCase.Encode(bytes); |
101 |
| - } |
102 |
| - |
103 |
| - /// <summary> |
104 |
| - /// Encodes stream of bytes into a Base16 text. |
105 |
| - /// </summary> |
106 |
| - /// <param name="input">Stream that provides bytes to be encoded.</param> |
107 |
| - /// <param name="output">Stream that the encoded text is written to.</param> |
108 |
| - [Obsolete("Deprecated. Use Base16.UpperCase.Encode() instead")] |
109 |
| - public static void EncodeUpper(Stream input, TextWriter output) |
110 |
| - { |
111 |
| - UpperCase.Encode(input, output); |
112 |
| - } |
113 |
| - |
114 |
| - /// <summary> |
115 |
| - /// Encodes stream of bytes into a Base16 text. |
116 |
| - /// </summary> |
117 |
| - /// <param name="input">Stream that provides bytes to be encoded.</param> |
118 |
| - /// <param name="output">Stream that the encoded text is written to.</param> |
119 |
| - /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> |
120 |
| - [Obsolete("Deprecated. Use Base16.UpperCase.EncodeAsync instead")] |
121 |
| - public static Task EncodeUpperAsync(Stream input, TextWriter output) |
122 |
| - { |
123 |
| - return UpperCase.EncodeAsync(input, output); |
124 |
| - } |
125 |
| - |
126 |
| - /// <summary> |
127 |
| - /// Encodes stream of bytes into a Base16 text. |
128 |
| - /// </summary> |
129 |
| - /// <param name="input">Stream that provides bytes to be encoded.</param> |
130 |
| - /// <param name="output">Stream that the encoded text is written to.</param> |
131 |
| - [Obsolete("Deprecated. Use Base16.LowerCase.Encode() instead")] |
132 |
| - public static void EncodeLower(Stream input, TextWriter output) |
133 |
| - { |
134 |
| - LowerCase.Encode(input, output); |
135 |
| - } |
136 |
| - |
137 |
| - /// <summary> |
138 |
| - /// Encodes stream of bytes into a Base16 text. |
139 |
| - /// </summary> |
140 |
| - /// <param name="input">Stream that provides bytes to be encoded.</param> |
141 |
| - /// <param name="output">Stream that the encoded text is written to.</param> |
142 |
| - /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> |
143 |
| - [Obsolete("Deprecated. Use Base16.LowerCase.EncodeLower instead")] |
144 |
| - public static Task EncodeLowerAsync(Stream input, TextWriter output) |
145 |
| - { |
146 |
| - return LowerCase.EncodeAsync(input, output); |
147 |
| - } |
148 |
| - |
149 |
| - /// <summary> |
150 |
| - /// Decode Upper/Lowercase Base16 text into bytes. |
151 |
| - /// </summary> |
152 |
| - /// <param name="text">Hex string.</param> |
153 |
| - /// <returns>Decoded bytes.</returns> |
154 |
| - public static Span<byte> Decode(string text) |
155 |
| - { |
156 |
| - return UpperCase.Decode(text.AsSpan()); |
157 |
| - } |
| 81 | + /// <summary> |
| 82 | + /// Decode Upper/Lowercase Base16 text into bytes. |
| 83 | + /// </summary> |
| 84 | + /// <param name="text">Hex string.</param> |
| 85 | + /// <returns>Decoded bytes.</returns> |
| 86 | + public static Span<byte> Decode(string text) |
| 87 | + { |
| 88 | + return UpperCase.Decode(text.AsSpan()); |
| 89 | + } |
158 | 90 |
|
159 | 91 | /// <summary>
|
160 | 92 | /// Decode Base16 text through streams for generic use. Stream based variant tries to consume
|
|
0 commit comments