<commit_before>package scala.reactive
package remoting



import java.net._
import java.nio.ByteBuffer
import java.nio.channels.DatagramChannel
import scala.collection._
import scala.reactive.core.UnrolledRing



class Remoting(val system: IsoSystem) extends Protocol {
  object Udp extends Remoting.Transport {
    val datagramChannel = {
      val url = system.bundle.udpUrl
      val ch = DatagramChannel.open()
      ch.bind(url.inetSocketAddress)
      ch
    }

    def newChannel[@spec(Int, Long, Double) T](url: ChannelUrl): Channel[T] = {
      new UdpChannel[T](url)
    }

    def serialize(name: String, anchor: String, x: Any): ByteBuffer = {
      ???
    }

    private class UdpChannel[@spec(Int, Long, Double) T](url: ChannelUrl)
    extends Channel[T] {
      def !(x: T): Unit = {
        val bytes = serialize(url.isoUrl.name, url.anchor, x)
        val sysUrl = url.isoUrl.systemUrl
        datagramChannel.send(bytes, sysUrl.inetSocketAddress)
      }
    }
  }

  def resolve[@spec(Int, Long, Double) T](channelUrl: ChannelUrl): Channel[T] = {
    channelUrl.isoUrl.systemUrl.schema match {
      case "iso.udp" => Udp.newChannel[T](channelUrl)
      case s => sys.error("Unknown channel schema: $s")
    }
  }
}


object Remoting {
  trait Transport {
    def newChannel[@spec(Int, Long, Double) T](url: ChannelUrl): Channel[T]
  }
}<commit_msg>Add `ByteBuffer`-backed output stream.<commit_after>package scala.reactive
package remoting



import java.io.OutputStream
import java.net._
import java.nio.ByteBuffer
import java.nio.channels.DatagramChannel
import scala.collection._
import scala.reactive.core.UnrolledRing



class Remoting(val system: IsoSystem) extends Protocol {
  object Udp extends Remoting.Transport {
    val datagramChannel = {
      val url = system.bundle.udpUrl
      val ch = DatagramChannel.open()
      ch.bind(url.inetSocketAddress)
      ch
    }

    def newChannel[@spec(Int, Long, Double) T](url: ChannelUrl): Channel[T] = {
      new UdpChannel[T](url)
    }

    private def serialize(name: String, anchor: String, x: Any): ByteBuffer = {
      ???
    }

    private class UdpChannel[@spec(Int, Long, Double) T](url: ChannelUrl)
    extends Channel[T] {
      def !(x: T): Unit = {
        val bytes = serialize(url.isoUrl.name, url.anchor, x)
        val sysUrl = url.isoUrl.systemUrl
        datagramChannel.send(bytes, sysUrl.inetSocketAddress)
      }
    }
  }

  def resolve[@spec(Int, Long, Double) T](channelUrl: ChannelUrl): Channel[T] = {
    channelUrl.isoUrl.systemUrl.schema match {
      case "iso.udp" => Udp.newChannel[T](channelUrl)
      case s => sys.error("Unknown channel schema: $s")
    }
  }
}


object Remoting {
  trait Transport {
    def newChannel[@spec(Int, Long, Double) T](url: ChannelUrl): Channel[T]
  }

  private class ByteBufferOutputStream(val buf: ByteBuffer) extends OutputStream {
    def write(b: Int): Unit = buf.put(b.toByte)
    override def write(bytes: Array[Byte], off: Int, len: Int): Unit = {
      buf.put(bytes, off, len)
    }
    
  }
}
{'fraction_non_alphanumeric': 0.1219672131147541, 'fraction_numerical': 0.0, 'mean_word_length': 3.2375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1688028', 'n_tokens_mistral': 998, 'n_tokens_neox': 974, 'n_words': 236}