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

scala.scalanative.nir.serialization.package.scala Maven / Gradle / Ivy

There is a newer version: 0.5.6
Show newest version
package scala.scalanative
package nir

import java.io.OutputStream
import java.nio._

package object serialization {
  def serializeText(defns: Seq[Defn], buffer: ByteBuffer): Unit = {
    val builder = Show.newBuilder
    builder.defns_(defns)
    buffer.put(builder.toString.getBytes)
  }

  @inline
  private def withBigEndian[T](buf: ByteBuffer)(body: ByteBuffer => T): T = {
    val o = buf.order()
    buf.order(ByteOrder.BIG_ENDIAN)
    try body(buf)
    finally buf.order(o)
  }

  def serializeBinary(defns: Seq[Defn], out: OutputStream): Unit =
    new BinarySerializer().serialize(defns, out)

  def deserializeBinary(buffer: ByteBuffer, bufferName: String): Seq[Defn] =
    withBigEndian(buffer) {
      new BinaryDeserializer(_, bufferName).deserialize()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy