Skip to content

Commit 42d8495

Browse files
authored
Implement partial text decoding (#234)
1 parent bb16ab0 commit 42d8495

File tree

14 files changed

+1693
-174
lines changed

14 files changed

+1693
-174
lines changed

gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ gradle-kmp-configuration = "0.5.2"
66
gradle-kotlin = "2.2.21"
77
gradle-publish-maven = "0.35.0"
88

9+
kotlinx-coroutines = "1.10.2"
10+
911
[libraries]
1012
benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "gradle-benchmark" }
1113

@@ -14,6 +16,9 @@ gradle-kmp-configuration = { module = "io.matthewnelson:gradle-kmp-configurat
1416
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "gradle-kotlin" }
1517
gradle-publish-maven = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "gradle-publish-maven" }
1618

19+
# tests
20+
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
21+
1722
[plugins]
1823
benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "gradle-benchmark" }
1924
binary-compat = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "gradle-binary-compat" }

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ public class Base32CrockfordConfigBuilder {
263263
* }.newEncoderFeed { encodedChar ->
264264
* sb.append(encodedChar)
265265
* }.use { feed ->
266-
* bytes1.forEach { b -> feed.consume(b) }
266+
* bytes1.forEach(feed::consume)
267267
* feed.flush()
268-
* bytes2.forEach { b -> feed.consume(b) }
268+
* bytes2.forEach(feed::consume)
269269
* }
270270
* println(sb.toString())
271271
* // 91JP-RV3F-*41BP-YWKC-CGGG-*
@@ -280,9 +280,9 @@ public class Base32CrockfordConfigBuilder {
280280
* }.newEncoderFeed { encodedChar ->
281281
* sb.append(encodedChar)
282282
* }.use { feed ->
283-
* bytes1.forEach { b -> feed.consume(b) }
283+
* bytes1.forEach(feed::consume)
284284
* feed.flush()
285-
* bytes2.forEach { b -> feed.consume(b) }
285+
* bytes2.forEach(feed::consume)
286286
* }
287287
* println(sb.toString())
288288
* // 91JP-RV3F-41BP-YWKC-CGGG-*

library/core/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ fun main() {
2525

2626
Base64.Default.newEncoderFeed(outN).use { feed ->
2727
// Encode UTF-8 bytes to base64
28-
"Hello World 1!".decodeToByteArray(UTF8).forEach { b -> feed.consume(b) }
28+
"Hello World 1!".decodeToByteArray(UTF8).forEach(feed::consume)
2929
feed.flush() // Finalize first encoding to reuse the Feed
3030
outN.output('.') // Add a separator or something.
31-
"Hello World 2!".decodeToByteArray(UTF8).forEach { b -> feed.consume(b) }
31+
"Hello World 2!".decodeToByteArray(UTF8).forEach(feed::consume)
3232
} // << `Feed.use` extension function will call Feed.doFinal automatically
3333

3434
val encoded = sb.toString()
@@ -44,10 +44,10 @@ fun main() {
4444
// which will then pipe each "encoded" character of output to
4545
// the StringBuilder.
4646
Base64.Default.newDecoderFeed(feedUTF8::consume).use { feedB64 ->
47-
encoded.substringBefore('.').forEach { c -> feedB64.consume(c) }
47+
encoded.substringBefore('.').forEach(feedB64::consume)
4848
feedB64.flush() // Finalize first decoding to reuse the Feed
4949
feedUTF8.flush() // Prepare UTF8 feed for second decoding
50-
encoded.substringAfter('.').forEach { c -> feedB64.consume(c) }
50+
encoded.substringAfter('.').forEach(feedB64::consume)
5151
} // << `Feed.use` extension function will call Feed.doFinal automatically
5252
} // << `Feed.use` extension function will call Feed.doFinal automatically
5353

library/core/api/core.api

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,42 @@ public abstract class io/matthewnelson/encoding/core/Decoder {
33
public synthetic fun <init> (Lio/matthewnelson/encoding/core/EncoderDecoder$Config;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
44
public static final fun decodeBuffered (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
55
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
6+
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function3;)J
7+
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function3;)J
8+
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function3;)J
69
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
710
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
811
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
12+
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function3;)J
13+
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function3;)J
14+
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function3;)J
915
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
1016
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
1117
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
1218
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1319
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
20+
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
21+
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
22+
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1423
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1524
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1625
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
26+
public static final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
27+
public static final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
28+
public static final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1729
public static final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1830
public static final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1931
public static final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
2032
public static final fun decodeToByteArray (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;)[B
33+
public static final fun decodeToByteArray (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;II)[B
2134
public static final fun decodeToByteArray ([BLio/matthewnelson/encoding/core/Decoder;)[B
2235
public static final fun decodeToByteArray ([CLio/matthewnelson/encoding/core/Decoder;)[B
36+
public static final fun decodeToByteArray ([CLio/matthewnelson/encoding/core/Decoder;II)[B
2337
public static final fun decodeToByteArrayOrNull (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;)[B
38+
public static final fun decodeToByteArrayOrNull (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;II)[B
2439
public static final fun decodeToByteArrayOrNull ([BLio/matthewnelson/encoding/core/Decoder;)[B
2540
public static final fun decodeToByteArrayOrNull ([CLio/matthewnelson/encoding/core/Decoder;)[B
41+
public static final fun decodeToByteArrayOrNull ([CLio/matthewnelson/encoding/core/Decoder;II)[B
2642
public final fun getConfig ()Lio/matthewnelson/encoding/core/EncoderDecoder$Config;
2743
public final fun newDecoderFeed (Lio/matthewnelson/encoding/core/Decoder$OutFeed;)Lio/matthewnelson/encoding/core/Decoder$Feed;
2844
protected abstract fun newDecoderFeedProtected (Lio/matthewnelson/encoding/core/Decoder$OutFeed;)Lio/matthewnelson/encoding/core/Decoder$Feed;
@@ -31,26 +47,42 @@ public abstract class io/matthewnelson/encoding/core/Decoder {
3147
public final class io/matthewnelson/encoding/core/Decoder$Companion {
3248
public final fun decodeBuffered (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
3349
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
50+
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function3;)J
51+
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function3;)J
52+
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function3;)J
3453
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
3554
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
3655
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
56+
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function3;)J
57+
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function3;)J
58+
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function3;)J
3759
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
3860
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
3961
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
4062
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4163
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
64+
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
65+
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
66+
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4267
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4368
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4469
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
70+
public final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
71+
public final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
72+
public final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4573
public final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4674
public final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4775
public final fun decodeBufferedAsync ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
4876
public final fun decodeToByteArray (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;)[B
77+
public final fun decodeToByteArray (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;II)[B
4978
public final fun decodeToByteArray ([BLio/matthewnelson/encoding/core/Decoder;)[B
5079
public final fun decodeToByteArray ([CLio/matthewnelson/encoding/core/Decoder;)[B
80+
public final fun decodeToByteArray ([CLio/matthewnelson/encoding/core/Decoder;II)[B
5181
public final fun decodeToByteArrayOrNull (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;)[B
82+
public final fun decodeToByteArrayOrNull (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;II)[B
5283
public final fun decodeToByteArrayOrNull ([BLio/matthewnelson/encoding/core/Decoder;)[B
5384
public final fun decodeToByteArrayOrNull ([CLio/matthewnelson/encoding/core/Decoder;)[B
85+
public final fun decodeToByteArrayOrNull ([CLio/matthewnelson/encoding/core/Decoder;II)[B
5486
}
5587

5688
public abstract class io/matthewnelson/encoding/core/Decoder$Feed : io/matthewnelson/encoding/core/EncoderDecoder$Feed {
@@ -255,8 +287,10 @@ public final class io/matthewnelson/encoding/core/util/DecoderAction$Parser {
255287

256288
public final class io/matthewnelson/encoding/core/util/DecoderInput {
257289
public fun <init> (Ljava/lang/CharSequence;)V
290+
public fun <init> (Ljava/lang/CharSequence;II)V
258291
public fun <init> ([B)V
259292
public fun <init> ([C)V
293+
public fun <init> ([CII)V
260294
public final fun get (I)C
261295
}
262296

0 commit comments

Comments
 (0)