Fixed calculating message size

This commit is contained in:
dankito 2020-12-17 21:16:18 +01:00
parent b18edbf943
commit 361a4062cb
1 changed files with 10 additions and 6 deletions

View File

@ -35,8 +35,8 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
protected val utils: FinTsUtils = FinTsUtils()) { protected val utils: FinTsUtils = FinTsUtils()) {
companion object { companion object {
const val MessageHeaderLength = 30 const val MessageHeaderMinLength = 30
const val MessageEndingLength = 11
const val AddedSeparatorsLength = 3 const val AddedSeparatorsLength = 3
} }
@ -411,13 +411,17 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
val formattedPayload = formatPayload(payloadSegments) val formattedPayload = formatPayload(payloadSegments)
val messageSize = formattedPayload.length + MessageHeaderLength + MessageEndingLength + AddedSeparatorsLength val ending = Nachrichtenabschluss(generator.getNextSegmentNumber(), dialogContext)
val formattedEnding = ending.format()
val minMessageSize = formattedPayload.length + MessageHeaderMinLength + formattedEnding.length + AddedSeparatorsLength
val headerWithMinMessageSize = Nachrichtenkopf(ISegmentNumberGenerator.FirstSegmentNumber, minMessageSize, dialogContext).format()
val messageSize = formattedPayload.length + headerWithMinMessageSize.length + formattedEnding.length + AddedSeparatorsLength
val header = Nachrichtenkopf(ISegmentNumberGenerator.FirstSegmentNumber, messageSize, dialogContext) val header = Nachrichtenkopf(ISegmentNumberGenerator.FirstSegmentNumber, messageSize, dialogContext)
val ending = Nachrichtenabschluss(generator.getNextSegmentNumber(), dialogContext) return listOf(header.format(), formattedPayload, formattedEnding)
return listOf(header.format(), formattedPayload, ending.format())
.joinToString(Separators.SegmentSeparator, postfix = Separators.SegmentSeparator) .joinToString(Separators.SegmentSeparator, postfix = Separators.SegmentSeparator)
} }