From ff59c14c173d575b4e193e42d06a73b82fff1ccb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 5 Nov 2019 21:42:29 +0300 Subject: [PATCH] Minor fix to multipart envelope --- .../kotlin/hep/dataforge/io/EnvelopeParts.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt index ca4efea4..0a8a207d 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt @@ -17,6 +17,9 @@ object EnvelopeParts { const val PARTS_DATA_TYPE = "envelope.parts" } +/** + * Append multiple serialized envelopes to the data block. Previous data is erased if it was present + */ fun EnvelopeBuilder.parts(formatFactory: EnvelopeFormatFactory, envelopes: Collection) { dataType = PARTS_DATA_TYPE meta { @@ -36,7 +39,10 @@ fun EnvelopeBuilder.parts(formatFactory: EnvelopeFormatFactory, envelopes: Colle fun EnvelopeBuilder.parts(formatFactory: EnvelopeFormatFactory, builder: suspend SequenceScope.() -> Unit) = parts(formatFactory, sequence(builder).toList()) -fun Envelope.parts(io: IOPlugin = Global.plugins.fetch(IOPlugin)): Sequence { +/** + * If given envelope supports multipart data, return a sequence of those parts (could be empty). Otherwise return null. + */ +fun Envelope.parts(io: IOPlugin = Global.plugins.fetch(IOPlugin)): Sequence? { return when (dataType) { PARTS_DATA_TYPE -> { val size = meta[SIZE_KEY].int ?: error("Unsized parts not supported yet") @@ -55,6 +61,6 @@ fun Envelope.parts(io: IOPlugin = Global.plugins.fetch(IOPlugin)): Sequence emptySequence() + else -> null } }