All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.ktor.util.Encoders.kt Maven / Gradle / Ivy

Go to download

Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.

The newest version!
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.util

import io.ktor.utils.io.*
import kotlin.coroutines.*

/**
 * Empty [Encoder] that doesn't do any changes.
 */
public object Identity : Encoder {
    override fun encode(
        source: ByteReadChannel,
        coroutineContext: CoroutineContext
    ): ByteReadChannel = source

    override fun encode(
        source: ByteWriteChannel,
        coroutineContext: CoroutineContext
    ): ByteWriteChannel = source

    override fun decode(
        source: ByteReadChannel,
        coroutineContext: CoroutineContext
    ): ByteReadChannel = source
}

/**
 * Content encoder.
 */
public interface Encoder {
    /**
     * Launch coroutine to encode [source] bytes.
     */
    public fun encode(
        source: ByteReadChannel,
        coroutineContext: CoroutineContext = EmptyCoroutineContext
    ): ByteReadChannel

    /**
     * Launch coroutine to encode [source] bytes.
     */
    public fun encode(
        source: ByteWriteChannel,
        coroutineContext: CoroutineContext = EmptyCoroutineContext
    ): ByteWriteChannel

    /**
     * Launch coroutine to decode [source] bytes.
     */
    public fun decode(
        source: ByteReadChannel,
        coroutineContext: CoroutineContext = EmptyCoroutineContext
    ): ByteReadChannel
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy