2
2
using System . Collections . Generic ;
3
3
using System . Collections . Immutable ;
4
4
using System . Text ;
5
- using Fs . Binary . Codecs . Common ;
5
+ using Fs . Binary . Codecs . Settings ;
6
+ using Fs . Binary . Codecs . Settings . Providers ;
6
7
7
8
namespace Fs . Binary . Codecs . Base16
8
9
{
9
- public class Base16Settings : ExposedAlphabetBuilder
10
+ public class Base16Settings : SettingsBase , ISettingsAlphabet , ISettingsDecodingAffixes , ISettingsEncodingAffixes ,
11
+ ISettingsEncodingLines , ISettingsDecodingCheckFinalQuantum
10
12
{
13
+ private const int AlphabetSize = 16 ;
11
14
private static readonly string [ ] DefaultAlphabet = new string [ ]
12
15
{
13
16
"0123456789ABCDEF" ,
@@ -16,17 +19,41 @@ public class Base16Settings : ExposedAlphabetBuilder
16
19
17
20
public static readonly Base16Settings Default = new Base16Settings ( )
18
21
{
19
- IsReadOnly = true
22
+ Alphabets = DefaultAlphabet ,
23
+ IsProtected = true
20
24
} ;
21
25
22
- public Base16Settings ( )
23
- : base ( 16 , DefaultAlphabet )
26
+ private readonly SettingsFlagsProvider _flagsProvider ;
27
+ private readonly SettingsAlphabetProvider _alphabetProvider ;
28
+ private readonly SettingsDecodingAffixesProvider _decodingAffixes ;
29
+ private readonly SettingsEncodingAffixProvider _encodingAffixes ;
30
+ private readonly SettingsEncodingLinesProvider _encodingLines ;
31
+ private readonly SettingsDecodingCheckFinalQuantumProvider _decodingFinalQuantumProvider ;
32
+
33
+ private Base16Settings ( )
34
+ : base ( )
24
35
{
36
+ _alphabetProvider = new SettingsAlphabetProvider ( this , AlphabetSize ) ;
37
+ _decodingAffixes = new SettingsDecodingAffixesProvider ( this ) ;
38
+ _encodingAffixes = new SettingsEncodingAffixProvider ( this ) ;
39
+ _encodingLines = new SettingsEncodingLinesProvider ( this ) ;
40
+ _decodingFinalQuantumProvider = new SettingsDecodingCheckFinalQuantumProvider ( this ) ;
41
+ _flagsProvider = new SettingsFlagsProvider ( this ) ;
25
42
}
26
43
27
- public Base16Settings ( Base16Settings inheritedSettings , bool isProtected )
28
- : base ( inheritedSettings , isProtected )
44
+ public Base16Settings ( Base16Settings inheritedSettings )
45
+ : this ( )
29
46
{
47
+ if ( inheritedSettings == null )
48
+ throw new ArgumentNullException ( nameof ( inheritedSettings ) ) ;
49
+
50
+ InheritSettings ( inheritedSettings ) ;
51
+ }
52
+
53
+ private Base16Settings ( Base16Settings inheritedSettings , bool isProtected )
54
+ : this ( inheritedSettings )
55
+ {
56
+ IsProtected = isProtected ;
30
57
}
31
58
32
59
internal void GetEncoderSettings ( out string alphabet ,
@@ -36,12 +63,12 @@ internal void GetEncoderSettings ( out string alphabet,
36
63
out string initialPrefix ,
37
64
out string finalPrefix )
38
65
{
39
- alphabet = GetAlphabet ( ) ;
40
- flags = GetFlags ( ) ;
41
- lineSeparator = GetLineSeparator ( ) ;
42
- maximumLineLength = GetMaximumLineLength ( ) ;
43
- initialPrefix = GetEncodingPrefix ( ) ;
44
- finalPrefix = GetEncodingPostfix ( ) ;
66
+ alphabet = _alphabetProvider . GetEncodingAlphabet ( ) ;
67
+ flags = _flagsProvider . GetFlags ( ) ;
68
+ lineSeparator = _encodingLines . GetEncodingLineSeparator ( ) ;
69
+ maximumLineLength = _encodingLines . GetEncodingMaximumLineLength ( ) ;
70
+ initialPrefix = _encodingAffixes . GetEncodingPrefix ( ) ;
71
+ finalPrefix = _encodingAffixes . GetEncodingPostfix ( ) ;
45
72
}
46
73
47
74
internal void GetDecoderSettings ( out ImmutableArray < byte > decodingTable ,
@@ -50,13 +77,33 @@ internal void GetDecoderSettings ( out ImmutableArray<byte> decodingTable,
50
77
out ImmutableArray < string > decodingPostfixes ,
51
78
out int flags )
52
79
{
53
- decodingTable = GetDecodingTable ( ) ;
54
- decodingAffixTable = GetDecodingAffixTable ( ) ;
55
- decodingPrefixes = GetDecodingPrefixes ( ) ;
56
- decodingPostfixes = GetDecodingPostfixes ( ) ;
57
- flags = GetFlags ( ) ;
80
+ decodingTable = _alphabetProvider . GetDecodingTable ( ) ;
81
+ decodingAffixTable = _decodingAffixes . GetDecodingTable ( ) ;
82
+ decodingPrefixes = _decodingAffixes . GetDecodingPrefixes ( ) ;
83
+ decodingPostfixes = _decodingAffixes . GetDecodingPostfixes ( ) ;
84
+ flags = _flagsProvider . GetFlags ( ) ;
58
85
}
59
86
60
- public Base16Settings ToReadOnly ( ) => new Base16Settings ( this , true ) ;
87
+ // GetHexEncoding / GetHexDecoding are used by other encodings to encode/decode hexadecimal values
88
+ internal string GetHexEncoding ( ) => _alphabetProvider . GetEncodingAlphabet ( ) ;
89
+ internal ImmutableArray < byte > GetHexDecoding ( ) => _alphabetProvider . GetDecodingTable ( ) ;
90
+
91
+ public Base16Settings ToReadOnly ( ) => ( IsProtected ) ? this : new Base16Settings ( this , true ) ;
92
+
93
+ public string [ ] Alphabets { get => _alphabetProvider . Alphabets ; set => _alphabetProvider . Alphabets = value ; }
94
+ public string DecodingIgnorableCharacters { get => _alphabetProvider . DecodingIgnorableCharacters ; set => _alphabetProvider . DecodingIgnorableCharacters = value ; }
95
+ public bool DecodingIgnoreInvalidCharacters { get => _alphabetProvider . DecodingIgnoreInvalidCharacters ; set => _alphabetProvider . DecodingIgnoreInvalidCharacters = value ; }
96
+ public string [ ] DecodingPrefixes { get => _decodingAffixes . DecodingPrefixes ; set => _decodingAffixes . DecodingPrefixes = value ; }
97
+ public string [ ] DecodingPostfixes { get => _decodingAffixes . DecodingPostfixes ; set => _decodingAffixes . DecodingPostfixes = value ; }
98
+ public bool DecodingPrefixRequired { get => _decodingAffixes . DecodingPrefixRequired ; set => _decodingAffixes . DecodingPrefixRequired = value ; }
99
+ public bool DecodingPostfixRequired { get => _decodingAffixes . DecodingPostfixRequired ; set => _decodingAffixes . DecodingPostfixRequired = value ; }
100
+ public int DecodingMinimumInputBuffer => _decodingAffixes . DecodingMinimumInputBuffer ;
101
+ public string EncodingPrefix { get => _encodingAffixes . EncodingPrefix ; set => _encodingAffixes . EncodingPrefix = value ; }
102
+ public string EncodingPostfix { get => _encodingAffixes . EncodingPostfix ; set => _encodingAffixes . EncodingPostfix = value ; }
103
+ public int EncodingAffixLength => _encodingAffixes . EncodingAffixLength ;
104
+ public string EncodingLineSeparator { get => _encodingLines . EncodingLineSeparator ; set => _encodingLines . EncodingLineSeparator = value ; }
105
+ public int EncodingMaximumLineLength { get => _encodingLines . EncodingMaximumLineLength ; set => _encodingLines . EncodingMaximumLineLength = value ; }
106
+ public bool EncodingRequireTerminalLineSeparator { get => _encodingLines . EncodingRequireTerminalLineSeparator ; set => _encodingLines . EncodingRequireTerminalLineSeparator = value ; }
107
+ public bool DecodingIgnoreInvalidFinalQuantum { get => _decodingFinalQuantumProvider . DecodingIgnoreInvalidFinalQuantum ; set => _decodingFinalQuantumProvider . DecodingIgnoreInvalidFinalQuantum = value ; }
61
108
}
62
109
}
0 commit comments