
commonMain.maryk.core.protobuf.WriteCache.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core-jvm Show documentation
Show all versions of core-jvm Show documentation
Maryk is a Kotlin Multiplatform library which helps you to store, query and send data in a structured way over multiple platforms. The data store stores any value with a version, so it is possible to request only the changed data or live listen for updates.
The newest version!
package maryk.core.protobuf
import maryk.core.properties.IsPropertyContext
/**
* Cache to store calculated lengths and contexts in for later ProtoBuf writing phase
*/
class WriteCache : WriteCacheReader, WriteCacheWriter {
private val lengths = mutableListOf()
private var lengthCacheIndex = 0
private val contexts = mutableListOf()
private var contextCacheIndex = 0
override fun addLengthToCache(item: ByteLengthContainer) {
lengths += item
}
override fun addContextToCache(item: CX) {
contexts += item
}
override fun nextLengthFromCache() = lengths[lengthCacheIndex++].length
override fun nextContextFromCache() = contexts[contextCacheIndex++]
}
interface WriteCacheWriter {
fun addLengthToCache(item: ByteLengthContainer)
fun addContextToCache(item: CX)
}
interface WriteCacheReader {
fun nextLengthFromCache(): Int
fun nextContextFromCache(): IsPropertyContext
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy