diff --git a/build.gradle.kts b/build.gradle.kts index 7f190853..430fcda4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { id("scientifik.publish") version "0.2.2" apply false } -val dataforgeVersion by extra("0.1.5-dev-2") +val dataforgeVersion by extra("0.1.5-dev-3") val bintrayRepo by extra("dataforge") val githubProject by extra("dataforge-core") diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/IOFormat.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/IOFormat.kt index bd1e54f4..e5497365 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/IOFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/IOFormat.kt @@ -79,8 +79,10 @@ inline fun buildPacketWithoutPool(headerSizeHint: Int = 0, block: BytePacketBuil } fun IOFormat.writePacket(obj: T): ByteReadPacket = buildPacket { writeObject(obj) } -//TODO Double buffer copy. fix all that with IO-2 + +@Deprecated("Not to be used outside tests due to double buffer write") fun IOFormat.writeBytes(obj: T): ByteArray = buildPacket { writeObject(obj) }.readBytes() +@Deprecated("Not to be used outside tests due to double buffer write") fun IOFormat.readBytes(array: ByteArray): T = buildPacket { writeFully(array) }.readObject() object DoubleIOFormat : IOFormat, IOFormatFactory { diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaggedEnvelopeFormat.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaggedEnvelopeFormat.kt index a95b7bfb..a461d257 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaggedEnvelopeFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaggedEnvelopeFormat.kt @@ -38,15 +38,15 @@ class TaggedEnvelopeFormat( override fun Output.writeEnvelope(envelope: Envelope, metaFormatFactory: MetaFormatFactory, formatMeta: Meta) { val metaFormat = metaFormatFactory.invoke(formatMeta, io.context) - val metaBytes = metaFormat.writeBytes(envelope.meta) + val metaBytes = metaFormat.writePacket(envelope.meta) val actualSize: ULong = if (envelope.data == null) { 0u } else { envelope.data?.size ?: ULong.MAX_VALUE } - val tag = Tag(metaFormatFactory.key, metaBytes.size.toUInt() + 2u, actualSize) + val tag = Tag(metaFormatFactory.key, metaBytes.remaining.toUInt() + 2u, actualSize) writePacket(tag.toBytes()) - writeFully(metaBytes) + writePacket(metaBytes) writeText("\r\n") envelope.data?.read { copyTo(this@writeEnvelope) } flush() diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt index d3953a0c..5c4b7dae 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/TaglessEnvelopeFormat.kt @@ -37,10 +37,10 @@ class TaglessEnvelopeFormat( //Printing meta if (!envelope.meta.isEmpty()) { - val metaBytes = metaFormat.writeBytes(envelope.meta) - writeProperty(META_LENGTH_PROPERTY, metaBytes.size) + val metaBytes = metaFormat.writePacket(envelope.meta) + writeProperty(META_LENGTH_PROPERTY, metaBytes.remaining) writeText(metaStart + "\r\n") - writeFully(metaBytes) + writePacket(metaBytes) writeText("\r\n") }