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

akka.io.dns.internal.RecordTypeSerializer.scala Maven / Gradle / Ivy

/*
 * Copyright (C) 2018-2020 Lightbend Inc. 
 */

package akka.io.dns.internal

import akka.io.dns.RecordType
import akka.util.{ ByteIterator, ByteStringBuilder, OptionVal }

/**
 * INTERNAL API
 */
private[akka] object RecordTypeSerializer {

  // TODO other type than ByteStringBuilder? (was used in akka-dns)
  def write(out: ByteStringBuilder, value: RecordType): Unit = {
    out.putShort(value.code)
  }

  def parse(it: ByteIterator): RecordType = {
    val id = it.getShort
    RecordType(id) match {
      case OptionVal.None    => throw new IllegalArgumentException(s"Illegal id [$id] for DnsRecordType")
      case OptionVal.Some(t) => t
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy