Skip to content

Commit ab78663

Browse files
authored
Add requirement that EncoderDecoder.Config.maxDecodeEmit be less than 256 (#215)
1 parent 1d3e911 commit ab78663

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/EncoderDecoder.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ public abstract class EncoderDecoder<C: EncoderDecoder.Config>(config: C): Encod
9494
* replacement byte sequence being used, can emit more; its maximum emission size is
9595
* required to be calculated, such as `(replacementStrategy.size * 2).coerceAtLeast(4)`.
9696
*
97-
* Value will be greater than `0`, or `-1` which indicates that the [EncoderDecoder.Config]
98-
* implementation has not updated to the new constructor introduced in version `2.6.0` and
99-
* as such is unable to be used with `:core` module APIs dependent on this value (such as
100-
* [Decoder.decodeBuffered] or [Decoder.decodeBufferedAsync]).
97+
* Value will be between `1` and `255` (inclusive), or `-1` which indicates that the
98+
* [EncoderDecoder.Config] implementation has not updated to the new constructor introduced
99+
* in version `2.6.0` and as such is unable to be used with `:core` module APIs dependent
100+
* on this value (such as [Decoder.decodeBuffered] or [Decoder.decodeBufferedAsync]).
101101
* */
102102
@JvmField
103103
public val maxDecodeEmit: Int,
@@ -126,7 +126,7 @@ public abstract class EncoderDecoder<C: EncoderDecoder.Config>(config: C): Encod
126126
/**
127127
* Instantiates a new [Config] instance.
128128
*
129-
* @throws [IllegalArgumentException] If [maxDecodeEmit] is less than `1`.
129+
* @throws [IllegalArgumentException] If [maxDecodeEmit] is less than `1` or greater than `255`.
130130
* */
131131
protected constructor(
132132
isLenient: Boolean?,
@@ -143,6 +143,7 @@ public abstract class EncoderDecoder<C: EncoderDecoder.Config>(config: C): Encod
143143
unused = null,
144144
) {
145145
require(maxDecodeEmit > 0) { "maxDecodeEmit must be greater than 0" }
146+
require(maxDecodeEmit < 256) { "maxDecodeEmit must be less than 256" }
146147
}
147148

148149
/**

library/core/src/commonTest/kotlin/io/matthewnelson/encoding/core/EncoderDecoderConfigUnitTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ class EncoderDecoderConfigUnitTest {
5858
val config = TestConfig(
5959
encodeReturn = { -1L },
6060
decodeInputReturn = { -1 },
61-
decodeReturn = { -1L }
61+
decodeReturn = { -1L },
62+
maxDecodeEmit = 255,
6263
)
6364

6465
assertFailsWith<EncodingSizeException> { config.decodeOutMaxSize(5) }
6566
assertFailsWith<EncodingSizeException> { config.decodeOutMaxSizeOrFail(DecoderInput("a")) }
6667
assertFailsWith<EncodingSizeException> { config.encodeOutMaxSize(5) }
6768
assertFailsWith<IllegalArgumentException> { TestConfig(maxDecodeEmit = 0) }
6869
assertFailsWith<IllegalArgumentException> { TestConfig(maxDecodeEmit = -1) }
70+
assertFailsWith<IllegalArgumentException> { TestConfig(maxDecodeEmit = 256) }
6971
}
7072

7173
@Test

0 commit comments

Comments
 (0)