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

moe.sdl.ipdb.parser.Parser.kt Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package moe.sdl.ipdb.parser

import moe.sdl.ipdb.parser.builtins.FullInfo

/**
 * IPDB Parser
 */
public sealed interface Parser

/**
 * [OrderParser] takes values sequentially,
 * which is good for performance, but lacks compatibility,
 * so there is no default implementation for it.
 *
 * If you're picky about performance,
 * you can implement it manually like this:
 *
 * ```kotlin
 * @Serializable
 * data class IdcInfo(
 *     val countryName: String,
 *     val regionName: String,
 *     val cityName: String,
 *     val ownerDomain: String,
 *     val ispDomain: String,
 *     val idc: String
 * ) : OrderParser {
 *     companion object {
 *         override fun parse(data: List): IdcInfo =
 *             IdcInfo(
 *             countryName = buff[0],
 *             regionName = buff[1],
 *             cityName = buff[2],
 *             ownerDomain = buff[3],
 *             ispDomain = buff[4],
 *             idc = buff[5],
 *         )
 *     }
 * }
 * ```
 *
 * @see PairParser
 */
public interface OrderParser {
    public fun parse(data: List): T
}

/**
 * [PairParser] takes values by key-value pairs,
 * thus allowing for better compatibility, but not for performance.
 *
 * [FullInfo] is the default implementation for such purpose.
 *
 * @see OrderParser
 * @see FullInfo
 */
public interface PairParser {
    public fun parsePairs(data: List>): T
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy