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

p-sim-ecu.doip-sim-ecu-dsl.0.14.0.source-code.ResponseExtensions.kt Maven / Gradle / Ivy

Go to download

This is a kotlin based domain specific language (dsl), to quickly and intuitively write custom DoIP ECU simulations.

There is a newer version: 0.15.1
Show newest version
public enum class SequenceMode {
    STOP_AT_END,
    WRAP_AROUND
}

/**
 * Returns the given responses, advancing by one after each request, either wrapping around to the beginning,
 * or repeating the last one
 */
public fun RequestResponseData.sequence(vararg responses: String,
    mode: SequenceMode = SequenceMode.STOP_AT_END,
    startIndex: Int = 0
) {
    var sequenceIndex by caller.storedProperty { startIndex }
    respond(responses[sequenceIndex])
    sequenceIndex += 1
    when (mode) {
        SequenceMode.STOP_AT_END -> if (sequenceIndex >= responses.size) sequenceIndex = responses.size - 1
        SequenceMode.WRAP_AROUND -> sequenceIndex %= responses.size
    }
}

/**
 * Returns the given responses, advancing by one after each request, starting at the beginning when the end is reached
 */
public fun RequestResponseData.sequenceWrapAround(vararg responses: String): Unit =
    sequence(*responses, mode = SequenceMode.WRAP_AROUND)

/**
 * Returns the given responses, advancing by one after each request, repeating the last one when the end is reached
 */
public fun RequestResponseData.sequenceStopAtEnd(vararg responses: String): Unit =
    sequence(*responses, mode = SequenceMode.STOP_AT_END)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy