Skip to content

Commit b67a2ea

Browse files
authored
Add ability to configure LineBreakOutFeed.reset behavior when Encoder.Feed.flush is called (#216)
1 parent ab78663 commit b67a2ea

28 files changed

Lines changed: 269 additions & 71 deletions

File tree

library/base16/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Base16 (a.k.a. "hex") encoding/decoding in accordance with [RFC 4648 section 8][
66
val base16 = Base16.Builder {
77
isLenient(enable = true)
88
lineBreak(interval = 64)
9+
lineBreakReset(onFlush = true)
910
encodeLowercase(enable = true)
11+
backFillBuffers(enable = true)
1012
}
1113

1214
val text = "Hello World!"

library/base16/api/base16.api

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class io/matthewnelson/encoding/base16/Base16$Builder {
2424
public final fun encodeLowercase (Z)Lio/matthewnelson/encoding/base16/Base16$Builder;
2525
public final fun isLenient (Z)Lio/matthewnelson/encoding/base16/Base16$Builder;
2626
public final fun lineBreak (B)Lio/matthewnelson/encoding/base16/Base16$Builder;
27+
public final fun lineBreakReset (Z)Lio/matthewnelson/encoding/base16/Base16$Builder;
2728
public final fun strictSpec ()Lio/matthewnelson/encoding/base16/Base16$Builder;
2829
}
2930

@@ -36,7 +37,7 @@ public final class io/matthewnelson/encoding/base16/Base16$Config : io/matthewne
3637
public final field encodeLowercase Z
3738
public final field encodeToLowercase Z
3839
public final field isConstantTime Z
39-
public synthetic fun <init> (ZBZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
40+
public synthetic fun <init> (ZBZZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
4041
}
4142

4243
public final class io/matthewnelson/encoding/base16/Base16ConfigBuilder {

library/base16/api/base16.klib.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class io.matthewnelson.encoding.base16/Base16 : io.matthewnelson.encoding.
1818
final fun encodeLowercase(kotlin/Boolean): io.matthewnelson.encoding.base16/Base16.Builder // io.matthewnelson.encoding.base16/Base16.Builder.encodeLowercase|encodeLowercase(kotlin.Boolean){}[0]
1919
final fun isLenient(kotlin/Boolean): io.matthewnelson.encoding.base16/Base16.Builder // io.matthewnelson.encoding.base16/Base16.Builder.isLenient|isLenient(kotlin.Boolean){}[0]
2020
final fun lineBreak(kotlin/Byte): io.matthewnelson.encoding.base16/Base16.Builder // io.matthewnelson.encoding.base16/Base16.Builder.lineBreak|lineBreak(kotlin.Byte){}[0]
21+
final fun lineBreakReset(kotlin/Boolean): io.matthewnelson.encoding.base16/Base16.Builder // io.matthewnelson.encoding.base16/Base16.Builder.lineBreakReset|lineBreakReset(kotlin.Boolean){}[0]
2122
final fun strictSpec(): io.matthewnelson.encoding.base16/Base16.Builder // io.matthewnelson.encoding.base16/Base16.Builder.strictSpec|strictSpec(){}[0]
2223
}
2324

library/base16/src/commonMain/kotlin/io/matthewnelson/encoding/base16/Base16.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ import kotlin.jvm.JvmSynthetic
4040
* val base16 = Base16.Builder {
4141
* isLenient(enable = true)
4242
* lineBreak(interval = 64)
43+
* lineBreakReset(onFlush = true)
4344
* encodeLowercase(enable = true)
45+
* backFillBuffers(enable = true)
4446
* }
4547
*
4648
* val text = "Hello World!"
@@ -72,22 +74,26 @@ public class Base16: EncoderDecoder<Base16.Config> {
7274
if (other == null) return
7375
this._isLenient = other.isLenient ?: true
7476
this._lineBreakInterval = other.lineBreakInterval
77+
this._lineBreakResetOnFlush = other.lineBreakResetOnFlush
7578
this._encodeLowercase = other.encodeLowercase
7679
this._backFillBuffers = other.backFillBuffers
7780
}
7881

7982
@get:JvmSynthetic
80-
@set:JvmSynthetic
8183
internal var _isLenient: Boolean = true
84+
private set
8285
@get:JvmSynthetic
83-
@set:JvmSynthetic
8486
internal var _lineBreakInterval: Byte = 0
87+
private set
88+
@get:JvmSynthetic
89+
internal var _lineBreakResetOnFlush: Boolean = true
90+
private set
8591
@get:JvmSynthetic
86-
@set:JvmSynthetic
8792
internal var _encodeLowercase: Boolean = false
93+
private set
8894
@get:JvmSynthetic
89-
@set:JvmSynthetic
9095
internal var _backFillBuffers: Boolean = true
96+
private set
9197

9298
/**
9399
* DEFAULT: `true`
@@ -130,6 +136,13 @@ public class Base16: EncoderDecoder<Base16.Config> {
130136
* */
131137
public fun lineBreak(interval: Byte): Builder = apply { _lineBreakInterval = interval }
132138

139+
/**
140+
* DEFAULT: `true`
141+
*
142+
* @see [EncoderDecoder.Config.lineBreakResetOnFlush]
143+
* */
144+
public fun lineBreakReset(onFlush: Boolean): Builder = apply { _lineBreakResetOnFlush = onFlush }
145+
133146
/**
134147
* DEFAULT: `false`
135148
*
@@ -180,12 +193,14 @@ public class Base16: EncoderDecoder<Base16.Config> {
180193
public class Config private constructor(
181194
isLenient: Boolean,
182195
lineBreakInterval: Byte,
196+
lineBreakResetOnFlush: Boolean,
183197
@JvmField
184198
public val encodeLowercase: Boolean,
185199
backFillBuffers: Boolean,
186200
): EncoderDecoder.Config(
187201
isLenient,
188202
lineBreakInterval,
203+
lineBreakResetOnFlush,
189204
paddingChar = null,
190205
maxDecodeEmit = 1,
191206
backFillBuffers,
@@ -222,6 +237,7 @@ public class Base16: EncoderDecoder<Base16.Config> {
222237
internal val DEFAULT: Config = Config(
223238
isLenient = true,
224239
lineBreakInterval = 64,
240+
lineBreakResetOnFlush = true,
225241
encodeLowercase = false,
226242
backFillBuffers = true,
227243
)

library/base16/src/commonMain/kotlin/io/matthewnelson/encoding/base16/Builders.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public class Base16ConfigBuilder {
8686
isLenient = compat._isLenient
8787
lineBreakInterval = compat._lineBreakInterval
8888
encodeToLowercase = compat._encodeLowercase
89+
90+
// Prior to 2.6.0, behavior was broken whereby the
91+
// LineBreakOutFeed was not being reset whenever
92+
// Encoder.Feed.flush was called. This maintains
93+
// that behavior for consumers who have not updated
94+
// to the Builder API.
95+
compat.lineBreakReset(onFlush = false)
8996
}
9097

9198
/**

library/base16/src/commonMain/kotlin/io/matthewnelson/encoding/base16/internal/-Config.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ package io.matthewnelson.encoding.base16.internal
1919

2020
import io.matthewnelson.encoding.base16.Base16
2121

22-
internal inline fun ((Boolean, Byte, Boolean, Boolean) -> Base16.Config).build(
22+
internal inline fun ((Boolean, Byte, Boolean, Boolean, Boolean) -> Base16.Config).build(
2323
b: Base16.Builder,
2424
noinline base16: (Base16.Config, Any?) -> Base16,
2525
): Base16 {
2626
if (
2727
b._isLenient == Base16.DELEGATE.config.isLenient
2828
&& b._lineBreakInterval == Base16.DELEGATE.config.lineBreakInterval
29+
&& b._lineBreakResetOnFlush == Base16.DELEGATE.config.lineBreakResetOnFlush
2930
&& b._encodeLowercase == Base16.DELEGATE.config.encodeLowercase
3031
&& b._backFillBuffers == Base16.DELEGATE.config.backFillBuffers
3132
) {
@@ -34,6 +35,7 @@ internal inline fun ((Boolean, Byte, Boolean, Boolean) -> Base16.Config).build(
3435
val config = this(
3536
b._isLenient,
3637
b._lineBreakInterval,
38+
b._lineBreakResetOnFlush,
3739
b._encodeLowercase,
3840
b._backFillBuffers,
3941
)

library/base32/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ val crockford = Base32.Crockford.Builder {
88
encodeLowercase(enable = false)
99
hyphen(interval = 5)
1010
check(symbol = '~')
11+
backFillBuffers(enable = true)
1112
}
1213

1314
val text = "Hello World!"
@@ -25,8 +26,10 @@ assertEquals(text, decoded)
2526
val default = Base32.Default.Builder {
2627
isLenient(enable = true)
2728
lineBreak(interval = 64)
29+
lineBreakReset(onFlush = true)
2830
encodeLowercase(enable = false)
2931
padEncoded(enable = true)
32+
backFillBuffers(enable = true)
3033
}
3134

3235
val text = "Hello World!"
@@ -44,8 +47,10 @@ assertEquals(text, decoded)
4447
val hex = Base32.Hex.Builder {
4548
isLenient(enable = true)
4649
lineBreak(interval = 64)
50+
lineBreakReset(onFlush = true)
4751
encodeLowercase(enable = false)
4852
padEncoded(enable = true)
53+
backFillBuffers(enable = true)
4954
}
5055

5156
val text = "Hello World!"

library/base32/api/base32.api

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public final class io/matthewnelson/encoding/base32/Base32$Default$Builder {
118118
public final fun encodeLowercase (Z)Lio/matthewnelson/encoding/base32/Base32$Default$Builder;
119119
public final fun isLenient (Z)Lio/matthewnelson/encoding/base32/Base32$Default$Builder;
120120
public final fun lineBreak (B)Lio/matthewnelson/encoding/base32/Base32$Default$Builder;
121+
public final fun lineBreakReset (Z)Lio/matthewnelson/encoding/base32/Base32$Default$Builder;
121122
public final fun padEncoded (Z)Lio/matthewnelson/encoding/base32/Base32$Default$Builder;
122123
public final fun strictSpec ()Lio/matthewnelson/encoding/base32/Base32$Default$Builder;
123124
}
@@ -132,7 +133,7 @@ public final class io/matthewnelson/encoding/base32/Base32$Default$Config : io/m
132133
public final field encodeToLowercase Z
133134
public final field isConstantTime Z
134135
public final field padEncoded Z
135-
public synthetic fun <init> (ZBZZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
136+
public synthetic fun <init> (ZBZZZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
136137
}
137138

138139
public final class io/matthewnelson/encoding/base32/Base32$Hex : io/matthewnelson/encoding/base32/Base32 {
@@ -153,6 +154,7 @@ public final class io/matthewnelson/encoding/base32/Base32$Hex$Builder {
153154
public final fun encodeLowercase (Z)Lio/matthewnelson/encoding/base32/Base32$Hex$Builder;
154155
public final fun isLenient (Z)Lio/matthewnelson/encoding/base32/Base32$Hex$Builder;
155156
public final fun lineBreak (B)Lio/matthewnelson/encoding/base32/Base32$Hex$Builder;
157+
public final fun lineBreakReset (Z)Lio/matthewnelson/encoding/base32/Base32$Hex$Builder;
156158
public final fun padEncoded (Z)Lio/matthewnelson/encoding/base32/Base32$Hex$Builder;
157159
public final fun strictSpec ()Lio/matthewnelson/encoding/base32/Base32$Hex$Builder;
158160
}
@@ -167,7 +169,7 @@ public final class io/matthewnelson/encoding/base32/Base32$Hex$Config : io/matth
167169
public final field encodeToLowercase Z
168170
public final field isConstantTime Z
169171
public final field padEncoded Z
170-
public synthetic fun <init> (ZBZZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
172+
public synthetic fun <init> (ZBZZZZLkotlin/jvm/internal/DefaultConstructorMarker;)V
171173
}
172174

173175
public final class io/matthewnelson/encoding/base32/Base32CrockfordConfigBuilder {

library/base32/api/base32.klib.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ sealed class <#A: io.matthewnelson.encoding.core/EncoderDecoder.Config> io.matth
136136
final fun encodeLowercase(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Default.Builder // io.matthewnelson.encoding.base32/Base32.Default.Builder.encodeLowercase|encodeLowercase(kotlin.Boolean){}[0]
137137
final fun isLenient(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Default.Builder // io.matthewnelson.encoding.base32/Base32.Default.Builder.isLenient|isLenient(kotlin.Boolean){}[0]
138138
final fun lineBreak(kotlin/Byte): io.matthewnelson.encoding.base32/Base32.Default.Builder // io.matthewnelson.encoding.base32/Base32.Default.Builder.lineBreak|lineBreak(kotlin.Byte){}[0]
139+
final fun lineBreakReset(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Default.Builder // io.matthewnelson.encoding.base32/Base32.Default.Builder.lineBreakReset|lineBreakReset(kotlin.Boolean){}[0]
139140
final fun padEncoded(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Default.Builder // io.matthewnelson.encoding.base32/Base32.Default.Builder.padEncoded|padEncoded(kotlin.Boolean){}[0]
140141
final fun strictSpec(): io.matthewnelson.encoding.base32/Base32.Default.Builder // io.matthewnelson.encoding.base32/Base32.Default.Builder.strictSpec|strictSpec(){}[0]
141142
}
@@ -174,6 +175,7 @@ sealed class <#A: io.matthewnelson.encoding.core/EncoderDecoder.Config> io.matth
174175
final fun encodeLowercase(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Hex.Builder // io.matthewnelson.encoding.base32/Base32.Hex.Builder.encodeLowercase|encodeLowercase(kotlin.Boolean){}[0]
175176
final fun isLenient(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Hex.Builder // io.matthewnelson.encoding.base32/Base32.Hex.Builder.isLenient|isLenient(kotlin.Boolean){}[0]
176177
final fun lineBreak(kotlin/Byte): io.matthewnelson.encoding.base32/Base32.Hex.Builder // io.matthewnelson.encoding.base32/Base32.Hex.Builder.lineBreak|lineBreak(kotlin.Byte){}[0]
178+
final fun lineBreakReset(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Hex.Builder // io.matthewnelson.encoding.base32/Base32.Hex.Builder.lineBreakReset|lineBreakReset(kotlin.Boolean){}[0]
177179
final fun padEncoded(kotlin/Boolean): io.matthewnelson.encoding.base32/Base32.Hex.Builder // io.matthewnelson.encoding.base32/Base32.Hex.Builder.padEncoded|padEncoded(kotlin.Boolean){}[0]
178180
final fun strictSpec(): io.matthewnelson.encoding.base32/Base32.Hex.Builder // io.matthewnelson.encoding.base32/Base32.Hex.Builder.strictSpec|strictSpec(){}[0]
179181
}

0 commit comments

Comments
 (0)