Skip to content

Commit 2b77da3

Browse files
authored
Rename json-okio target variables to sink (#2226)
The Okio codebase names Sink/BufferedSink variables "sink", so this aligns the naming convention
1 parent cdb14b2 commit 2b77da3

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

formats/json-okio/commonMain/src/kotlinx/serialization/json/okio/OkioStreams.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import kotlinx.serialization.json.okio.internal.OkioSerialReader
1616
import okio.*
1717

1818
/**
19-
* Serializes the [value] with [serializer] into a [target] using JSON format and UTF-8 encoding.
19+
* Serializes the [value] with [serializer] into a [sink] using JSON format and UTF-8 encoding.
2020
*
2121
* @throws [SerializationException] if the given value cannot be serialized to JSON.
2222
* @throws [okio.IOException] If an I/O error occurs and sink can't be written to.
@@ -25,9 +25,9 @@ import okio.*
2525
public fun <T> Json.encodeToBufferedSink(
2626
serializer: SerializationStrategy<T>,
2727
value: T,
28-
target: BufferedSink
28+
sink: BufferedSink
2929
) {
30-
val writer = JsonToOkioStreamWriter(target)
30+
val writer = JsonToOkioStreamWriter(sink)
3131
try {
3232
encodeByWriter(writer, serializer, value)
3333
} finally {
@@ -36,16 +36,16 @@ public fun <T> Json.encodeToBufferedSink(
3636
}
3737

3838
/**
39-
* Serializes given [value] to a [target] using UTF-8 encoding and serializer retrieved from the reified type parameter.
39+
* Serializes given [value] to a [sink] using UTF-8 encoding and serializer retrieved from the reified type parameter.
4040
*
4141
* @throws [SerializationException] if the given value cannot be serialized to JSON.
4242
* @throws [okio.IOException] If an I/O error occurs and sink can't be written to.
4343
*/
4444
@ExperimentalSerializationApi
4545
public inline fun <reified T> Json.encodeToBufferedSink(
4646
value: T,
47-
target: BufferedSink
48-
): Unit = encodeToBufferedSink(serializersModule.serializer(), value, target)
47+
sink: BufferedSink
48+
): Unit = encodeToBufferedSink(serializersModule.serializer(), value, sink)
4949

5050

5151
/**

formats/json-okio/commonMain/src/kotlinx/serialization/json/okio/internal/OkioJsonStreams.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ import kotlinx.serialization.json.internal.JsonWriter
1111
import kotlinx.serialization.json.internal.SerialReader
1212
import okio.*
1313

14-
internal class JsonToOkioStreamWriter(private val target: BufferedSink) : JsonWriter {
14+
internal class JsonToOkioStreamWriter(private val sink: BufferedSink) : JsonWriter {
1515
override fun writeLong(value: Long) {
1616
write(value.toString())
1717
}
1818

1919
override fun writeChar(char: Char) {
20-
target.writeUtf8CodePoint(char.code)
20+
sink.writeUtf8CodePoint(char.code)
2121
}
2222

2323
override fun write(text: String) {
24-
target.writeUtf8(text)
24+
sink.writeUtf8(text)
2525
}
2626

2727
override fun writeQuoted(text: String) {
28-
target.writeUtf8CodePoint('"'.code)
28+
sink.writeUtf8CodePoint('"'.code)
2929
var lastPos = 0
3030
for (i in text.indices) {
3131
val c = text[i].code
3232
if (c < ESCAPE_STRINGS.size && ESCAPE_STRINGS[c] != null) {
33-
target.writeUtf8(text, lastPos, i) // flush prev
34-
target.writeUtf8(ESCAPE_STRINGS[c]!!)
33+
sink.writeUtf8(text, lastPos, i) // flush prev
34+
sink.writeUtf8(ESCAPE_STRINGS[c]!!)
3535
lastPos = i + 1
3636
}
3737
}
3838

39-
if (lastPos != 0) target.writeUtf8(text, lastPos, text.length)
40-
else target.writeUtf8(text)
41-
target.writeUtf8CodePoint('"'.code)
39+
if (lastPos != 0) sink.writeUtf8(text, lastPos, text.length)
40+
else sink.writeUtf8(text)
41+
sink.writeUtf8CodePoint('"'.code)
4242
}
4343

4444
override fun release() {

0 commit comments

Comments
 (0)