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

value.ProtocolMessageMap.kt Maven / Gradle / Ivy

package io.toolisticon.kotlin.avro.value

import io.toolisticon.kotlin.avro.model.wrapper.AvroProtocol.Message
import io.toolisticon.kotlin.avro.model.wrapper.AvroProtocol.OneWayMessage
import io.toolisticon.kotlin.avro.model.wrapper.AvroProtocol.TwoWayMessage
import org.apache.avro.Protocol

/**
 * Holds
 */
@JvmInline
value class ProtocolMessageMap(private val value: Map = emptyMap()) : Map by value {
  companion object {
    fun of(protocol: Protocol) = ProtocolMessageMap(
      value = buildMap {
        protocol.messages.values.map {
          if (it.isOneWay) {
            OneWayMessage(it)
          } else {
            TwoWayMessage(it)
          }
        }.forEach {
          put(it.name, it)
        }
      })
  }

  fun filterOneWay(): OneWayMessageMap = ProtocolMessageMap(
    value = value.values.filterIsInstance().associateBy { it.name }
  )

  fun filterTwoWay(): TwoWayMessageMap = ProtocolMessageMap(
    value = value.values.filterIsInstance().associateBy { it.name }
  )
}

/**
 * Alias for message map containing only one way.
 */
typealias OneWayMessageMap = ProtocolMessageMap

/**
 * Alias for message map containing only two way.
 */
typealias TwoWayMessageMap = ProtocolMessageMap




© 2015 - 2025 Weber Informatics LLC | Privacy Policy