Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote Feeds to stable #130

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ the encoding/decoding process into its individual parts, such that the medium
for which data is coming from or going to can be **anything**; `Feed`'s only
care about `Byte`(s) and `Char`(s)!

`Feed`s are currently annotated with `ExperimentalEncodingApi` and require an
`OptIn` to use directly.

```kotlin
// e.g. Concatenate multiple encodings
val sb = StringBuilder()
Expand All @@ -169,7 +166,6 @@ val sb = StringBuilder()
// encodings and preserve the counter.
val out = LineBreakOutFeed(interval = 64) { char -> sb.append(char) }

@OptIn(ExperimentalEncodingApi::class)
Base64.Default.newEncoderFeed(out).use { feed ->
"Hello World 1!".forEach { c -> feed.consume(c.code.toByte()) }
feed.flush()
Expand All @@ -185,7 +181,6 @@ println(sb.toString())
// e.g. Writing encoded data to a File in Java.
// NOTE: try/catch omitted for this example.

@OptIn(ExperimentalEncodingApi::class)
file.outputStream().use { oStream ->
Base64.Default.newEncoderFeed { encodedChar ->
// As encoded data comes out of the feed,
Expand Down Expand Up @@ -237,7 +232,6 @@ if (size > Int.MAX_VALUE.toLong()) {

val sb = StringBuilder(size.toInt())

@OptIn(ExperimentalEncodingApi::class)
file.inputStream().reader().use { iStreamReader ->
Base64.Default.newDecoderFeed { decodedByte ->
// As decoded data comes out of the feed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import kotlin.jvm.JvmSynthetic
* @see [Encoder.encodeToCharArray]
* @see [Encoder.encodeToByteArray]
* */
@OptIn(ExperimentalEncodingApi::class)
public class Base16(config: Base16.Config): EncoderDecoder<Base16.Config>(config) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import kotlin.jvm.JvmSynthetic
* @see [Encoder.encodeToCharArray]
* @see [Encoder.encodeToByteArray]
* */
@OptIn(ExperimentalEncodingApi::class)
public sealed class Base32<C: EncoderDecoder.Config>(config: C): EncoderDecoder<C>(config) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ package io.matthewnelson.encoding.base32
import io.matthewnelson.encoding.core.Decoder.Companion.decodeToByteArray
import io.matthewnelson.encoding.core.Decoder.Companion.decodeToByteArrayOrNull
import io.matthewnelson.encoding.core.Encoder.Companion.encodeToString
import io.matthewnelson.encoding.core.ExperimentalEncodingApi
import io.matthewnelson.encoding.core.use
import io.matthewnelson.encoding.test.BaseNEncodingTest
import kotlin.test.*

@OptIn(ExperimentalEncodingApi::class)
class Base32CrockfordUnitTest: BaseNEncodingTest() {

private var crockford: Base32.Crockford = Base32Crockford { checkSymbol(null) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import kotlin.jvm.JvmSynthetic
* @see [Encoder.encodeToCharArray]
* @see [Encoder.encodeToByteArray]
* */
@OptIn(ExperimentalEncodingApi::class)
public class Base64(config: Base64.Config): EncoderDecoder<Base64.Config>(config) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import io.matthewnelson.encoding.core.EncoderDecoder.Feed
* - Calling [Feed.close] if [block] **DID** throw an
* exception.
* */
@ExperimentalEncodingApi
@OptIn(ExperimentalContracts::class)
public inline fun <C: EncoderDecoder.Config, T: Feed<C>?, V> T.use(block: (T) -> V): V {
contract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
*
* @see [Decoder.Feed]
* */
@ExperimentalEncodingApi
public fun newDecoderFeed(out: Decoder.OutFeed): Decoder<C>.Feed {
// Reserved for future Decoder.OutFeed interception
return newDecoderFeedProtected(out)
Expand All @@ -83,9 +82,7 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
* @see [EncoderDecoder.Feed]
* @see [EncoderDecoder.Feed.doFinal]
* */
public abstract inner class Feed
@ExperimentalEncodingApi
constructor(): EncoderDecoder.Feed<C>(config) {
public abstract inner class Feed: EncoderDecoder.Feed<C>(config) {
private var isClosed = false
private var isPaddingSet = false

Expand All @@ -95,7 +92,6 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
* @throws [EncodingException] if [isClosed] is true, or if
* there was an error decoding.
* */
@ExperimentalEncodingApi
@Throws(EncodingException::class)
public fun consume(input: Char) {
if (isClosed) throw closedException()
Expand Down Expand Up @@ -140,7 +136,6 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
* @throws [EncodingException] if [isClosed] is true, or if
* there was an error decoding.
* */
@ExperimentalEncodingApi
@Throws(EncodingException::class)
public final override fun flush() {
if (isClosed) throw closedException()
Expand All @@ -154,7 +149,6 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
}
}

@ExperimentalEncodingApi
public final override fun close() { isClosed = true }
public final override fun isClosed(): Boolean = isClosed
public final override fun toString(): String = "${this@Decoder}.Decoder.Feed@${hashCode()}"
Expand Down Expand Up @@ -185,7 +179,6 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
@JvmStatic
@Throws(EncodingException::class)
public fun CharSequence.decodeToByteArray(decoder: Decoder<*>): ByteArray {
@OptIn(ExperimentalEncodingApi::class)
return decoder.decode(DecoderInput(this)) { feed ->
forEach { c ->
feed.consume(c)
Expand All @@ -212,7 +205,6 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
@JvmStatic
@Throws(EncodingException::class)
public fun CharArray.decodeToByteArray(decoder: Decoder<*>): ByteArray {
@OptIn(ExperimentalEncodingApi::class)
return decoder.decode(DecoderInput(this)) { feed ->
forEach { c ->
feed.consume(c)
Expand All @@ -239,7 +231,6 @@ public sealed class Decoder<C: EncoderDecoder.Config>(public val config: C) {
@JvmStatic
@Throws(EncodingException::class)
public fun ByteArray.decodeToByteArray(decoder: Decoder<*>): ByteArray {
@OptIn(ExperimentalEncodingApi::class)
return decoder.decode(DecoderInput(this)) { feed ->
forEach { b ->
feed.consume(b.toInt().toChar())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con
*
* @see [Encoder.Feed]
* */
@ExperimentalEncodingApi
public fun newEncoderFeed(out: Encoder.OutFeed): Encoder<C>.Feed {
return if (config.lineBreakInterval > 0 && out !is LineBreakOutFeed) {
newEncoderFeedProtected(LineBreakOutFeed(config.lineBreakInterval, out))
Expand Down Expand Up @@ -80,17 +79,14 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con
* @see [EncoderDecoder.Feed]
* @see [EncoderDecoder.Feed.doFinal]
* */
public abstract inner class Feed
@ExperimentalEncodingApi
constructor(): EncoderDecoder.Feed<C>(config) {
public abstract inner class Feed: EncoderDecoder.Feed<C>(config) {
private var isClosed = false

/**
* Updates the [Encoder.Feed] with a new byte to encode.
*
* @throws [EncodingException] if [isClosed] is true.
* */
@ExperimentalEncodingApi
@Throws(EncodingException::class)
public fun consume(input: Byte) {
if (isClosed) throw closedException()
Expand All @@ -112,7 +108,6 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con
* @see [EncoderDecoder.Feed.flush]
* @throws [EncodingException] if [isClosed] is true.
* */
@ExperimentalEncodingApi
@Throws(EncodingException::class)
public final override fun flush() {
if (isClosed) throw closedException()
Expand All @@ -127,7 +122,6 @@ public sealed class Encoder<C: EncoderDecoder.Config>(config: C): Decoder<C>(con
}
}

@ExperimentalEncodingApi
public final override fun close() { isClosed = true }
public final override fun isClosed(): Boolean = isClosed
public final override fun toString(): String = "${this@Encoder}.Encoder.Feed@${hashCode()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ import kotlin.jvm.JvmStatic
* @see [Encoder]
* @see [Decoder]
* */
public abstract class EncoderDecoder<C: EncoderDecoder.Config>
@ExperimentalEncodingApi
constructor(config: C): Encoder<C>(config) {
public abstract class EncoderDecoder<C: EncoderDecoder.Config>(config: C): Encoder<C>(config) {

/**
* Base configuration for an [EncoderDecoder]. More options
Expand All @@ -54,9 +52,7 @@ constructor(config: C): Encoder<C>(config) {
* used". If the encoding specification does not use padding,
* pass `null`.
* */
public abstract class Config
@ExperimentalEncodingApi
constructor(
public abstract class Config(
@JvmField
public val isLenient: Boolean?,
lineBreakInterval: Byte,
Expand Down Expand Up @@ -417,7 +413,6 @@ constructor(config: C): Encoder<C>(config) {
* @throws [EncodingException] if [isClosed] is true, or
* there was an error encoding/decoding.
* */
@ExperimentalEncodingApi
@Throws(EncodingException::class)
public abstract fun flush()

Expand All @@ -436,7 +431,6 @@ constructor(config: C): Encoder<C>(config) {
* @throws [EncodingException] if [isClosed] is true, or
* there was an error encoding/decoding.
* */
@ExperimentalEncodingApi
@Throws(EncodingException::class)
public fun doFinal() {
if (isClosed()) throw closedException()
Expand All @@ -462,7 +456,6 @@ constructor(config: C): Encoder<C>(config) {
*
* @see [use]
* */
@ExperimentalEncodingApi
public abstract fun close()

public abstract fun isClosed(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import kotlin.contracts.contract

@Suppress("NOTHING_TO_INLINE")
@Throws(EncodingException::class)
@OptIn(ExperimentalEncodingApi::class, ExperimentalContracts::class)
@OptIn(ExperimentalContracts::class)
internal inline fun <C: Config> Decoder<C>.decode(
input: DecoderInput,
action: (feed: Decoder<*>.Feed) -> Unit
Expand Down Expand Up @@ -82,7 +82,6 @@ internal inline fun <T: Any> Encoder<*>.encodeOutSizeOrFail(
}

@Suppress("NOTHING_TO_INLINE")
@OptIn(ExperimentalEncodingApi::class)
internal inline fun <C: Config> Encoder<C>.encode(
data: ByteArray,
out: Encoder.OutFeed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.matthewnelson.encoding.core.helpers.TestEncoderDecoder
import io.matthewnelson.encoding.core.util.LineBreakOutFeed
import kotlin.test.*

@OptIn(ExperimentalEncodingApi::class)
class EncoderDecoderFeedUnitTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
package io.matthewnelson.encoding.core.helpers

import io.matthewnelson.encoding.core.EncoderDecoder
import io.matthewnelson.encoding.core.ExperimentalEncodingApi
import io.matthewnelson.encoding.core.util.DecoderInput

@OptIn(ExperimentalEncodingApi::class)
class TestConfig(
isLenient: Boolean? = false,
lineBreakInterval: Byte = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package io.matthewnelson.encoding.core.helpers

import io.matthewnelson.encoding.core.*

@OptIn(ExperimentalEncodingApi::class)
class TestEncoderDecoder(
config: TestConfig,
private val encoderDoFinal: ((Encoder<TestConfig>.Feed) -> Unit)? = null,
Expand Down