Skip to content

Commit 40dcef0

Browse files
authored
Add Encoder.{encodeBuffered/encodeBufferedAsync} extension functions (#232)
1 parent dcd781a commit 40dcef0

File tree

13 files changed

+938
-201
lines changed

13 files changed

+938
-201
lines changed

library/core/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ fun main() {
5858
// Write UTF-8 encoded bytes to a FileStream (kmp-file:file)
5959
val file = "/path/to/file.txt".toFile()
6060
file.openWrite(excl = null).use { stream ->
61-
decoded.decodeBuffered(UTF8, action = stream::write)
61+
decoded.decodeBuffered(
62+
decoder = UTF8,
63+
throwOnOverflow = false,
64+
action = stream::write,
65+
)
6266
}
6367

6468
// Now do it asynchronously (kmp-file:async)
@@ -67,8 +71,9 @@ fun main() {
6771
file.openAppendAsync(excl = OpenExcl.MustExist)
6872
.useAsync { stream ->
6973
decoded.decodeBufferedAsync(
70-
maxBufSize = 1024,
7174
decoder = UTF8.ThrowOnInvalid,
75+
throwOnOverflow = false,
76+
maxBufSize = 1024,
7277
action = stream::writeAsync,
7378
)
7479
}

library/core/api/core.api

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
public abstract class io/matthewnelson/encoding/core/Decoder {
22
public static final field Companion Lio/matthewnelson/encoding/core/Decoder$Companion;
33
public synthetic fun <init> (Lio/matthewnelson/encoding/core/EncoderDecoder$Config;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
4+
public static final fun decodeBuffered (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
45
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
56
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
67
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
78
public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
89
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
910
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
1011
public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
12+
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1113
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1214
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
1315
public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -27,13 +29,15 @@ public abstract class io/matthewnelson/encoding/core/Decoder {
2729
}
2830

2931
public final class io/matthewnelson/encoding/core/Decoder$Companion {
32+
public final fun decodeBuffered (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
3033
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J
3134
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
3235
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
3336
public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
3437
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J
3538
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J
3639
public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J
40+
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
3741
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
3842
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
3943
public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -73,6 +77,12 @@ public final class io/matthewnelson/encoding/core/Decoder$OutFeed$Companion {
7377
public abstract class io/matthewnelson/encoding/core/Encoder : io/matthewnelson/encoding/core/Decoder {
7478
public static final field Companion Lio/matthewnelson/encoding/core/Encoder$Companion;
7579
public synthetic fun <init> (Lio/matthewnelson/encoding/core/EncoderDecoder$Config;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
80+
public static final fun encodeBuffered ([BLio/matthewnelson/encoding/core/Encoder;ZILkotlin/jvm/functions/Function3;)J
81+
public static final fun encodeBuffered ([BLio/matthewnelson/encoding/core/Encoder;ZLkotlin/jvm/functions/Function3;)J
82+
public static final fun encodeBuffered ([BLio/matthewnelson/encoding/core/Encoder;Z[CLkotlin/jvm/functions/Function3;)J
83+
public static final fun encodeBufferedAsync ([BLio/matthewnelson/encoding/core/Encoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
84+
public static final fun encodeBufferedAsync ([BLio/matthewnelson/encoding/core/Encoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
85+
public static final fun encodeBufferedAsync ([BLio/matthewnelson/encoding/core/Encoder;Z[CLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
7686
public static final fun encodeToByteArray ([BLio/matthewnelson/encoding/core/Encoder;)[B
7787
public static final fun encodeToCharArray ([BLio/matthewnelson/encoding/core/Encoder;)[C
7888
public static final fun encodeToString ([BLio/matthewnelson/encoding/core/Encoder;)Ljava/lang/String;
@@ -81,6 +91,12 @@ public abstract class io/matthewnelson/encoding/core/Encoder : io/matthewnelson/
8191
}
8292

8393
public final class io/matthewnelson/encoding/core/Encoder$Companion {
94+
public final fun encodeBuffered ([BLio/matthewnelson/encoding/core/Encoder;ZILkotlin/jvm/functions/Function3;)J
95+
public final fun encodeBuffered ([BLio/matthewnelson/encoding/core/Encoder;ZLkotlin/jvm/functions/Function3;)J
96+
public final fun encodeBuffered ([BLio/matthewnelson/encoding/core/Encoder;Z[CLkotlin/jvm/functions/Function3;)J
97+
public final fun encodeBufferedAsync ([BLio/matthewnelson/encoding/core/Encoder;ZILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
98+
public final fun encodeBufferedAsync ([BLio/matthewnelson/encoding/core/Encoder;ZLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
99+
public final fun encodeBufferedAsync ([BLio/matthewnelson/encoding/core/Encoder;Z[CLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
84100
public final fun encodeToByteArray ([BLio/matthewnelson/encoding/core/Encoder;)[B
85101
public final fun encodeToCharArray ([BLio/matthewnelson/encoding/core/Encoder;)[C
86102
public final fun encodeToString ([BLio/matthewnelson/encoding/core/Encoder;)Ljava/lang/String;
@@ -129,6 +145,7 @@ public abstract class io/matthewnelson/encoding/core/EncoderDecoder$Config {
129145
public final field lineBreakResetOnFlush Z
130146
public final field maxDecodeEmit I
131147
public final field maxEncodeEmit I
148+
public final field maxEncodeEmitWithLineBreak I
132149
public final field paddingChar Ljava/lang/Character;
133150
public fun <init> (Ljava/lang/Boolean;BLjava/lang/Character;)V
134151
protected fun <init> (Ljava/lang/Boolean;BZLjava/lang/Character;IIZ)V
@@ -137,6 +154,8 @@ public abstract class io/matthewnelson/encoding/core/EncoderDecoder$Config {
137154
public final fun decodeOutMaxSizeOrFail (Lio/matthewnelson/encoding/core/util/DecoderInput;)I
138155
protected abstract fun decodeOutMaxSizeOrFailProtected (ILio/matthewnelson/encoding/core/util/DecoderInput;)I
139156
protected abstract fun decodeOutMaxSizeProtected (J)J
157+
public final fun encodeOutMaxSize (I)I
158+
public final fun encodeOutMaxSize (IB)I
140159
public final fun encodeOutMaxSize (J)J
141160
public final fun encodeOutMaxSize (JB)J
142161
public final fun encodeOutSize (J)J

0 commit comments

Comments
 (0)