本文整理汇总了Scala中scala.scalajs.js.typedarray.ArrayBuffer类的典型用法代码示例。如果您正苦于以下问题:Scala ArrayBuffer类的具体用法?Scala ArrayBuffer怎么用?Scala ArrayBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayBuffer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TorrentStreamApi
//设置package包名称以及导入依赖的类
package com.karasiq.torrentstream.frontend
import boopickle.Default._
import org.scalajs.dom.ext.Ajax
import org.scalajs.dom.raw.XMLHttpRequest
import scala.concurrent.Future
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
object TorrentStreamApi {
private def readBinary[T: Pickler](xhr: XMLHttpRequest): T = {
Unpickle[T].fromBytes(TypedArrayBuffer.wrap(xhr.response.asInstanceOf[ArrayBuffer]))
}
def upload(data: Ajax.InputData): Future[TorrentInfo] = {
Ajax.post("/upload", data, responseType = "arraybuffer")
.map(readBinary[TorrentInfo])
}
def uploaded(): Future[Int] = {
Ajax.get("/info", responseType = "arraybuffer")
.map(readBinary[Int])
}
def info(offset: Int, count: Int): Future[Vector[TorrentInfo]] = {
Ajax.get(s"/info?offset=$offset&count=$count", responseType = "arraybuffer")
.map(readBinary[Vector[TorrentInfo]])
}
def remove(infoHash: String): Future[Unit] = {
Ajax.delete(s"/torrent?hash=$infoHash").map(_ ? ())
}
}
开发者ID:Karasiq,项目名称:torrentstream,代码行数:35,代码来源:TorrentStreamApi.scala
示例2: WebWorkerTransport
//设置package包名称以及导入依赖的类
package suzaku.platform.web
import java.nio.ByteBuffer
import suzaku.platform.Transport
import org.scalajs.dom
import org.scalajs.dom.webworkers.{DedicatedWorkerGlobalScope, Worker}
import scala.scalajs.js
import scala.scalajs.js.typedarray.TypedArrayBufferOps._
import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
abstract class WebWorkerTransport extends Transport {
private val emptyHandler = (data: ByteBuffer) => ()
private var dataHandler: ByteBuffer => Unit = emptyHandler
override def subscribe(handler: ByteBuffer => Unit): () => Unit = {
dataHandler = handler
// return an unsubscribing function
() =>
{
// restore our empty handler when called
dataHandler = emptyHandler
}
}
def receive(data: ArrayBuffer): Unit = dataHandler(TypedArrayBuffer.wrap(data))
}
class WorkerTransport(worker: DedicatedWorkerGlobalScope) extends WebWorkerTransport {
override def send(data: ByteBuffer): Unit = {
assert(data.hasTypedArray())
val out = data.typedArray.buffer.slice(0, data.limit())
worker.postMessage(out, js.Array(out).asInstanceOf[js.UndefOr[js.Array[dom.raw.Transferable]]])
}
}
class WorkerClientTransport(worker: Worker) extends WebWorkerTransport {
override def send(data: ByteBuffer): Unit = {
assert(data.hasTypedArray())
val out = data.typedArray.buffer.slice(0, data.limit())
worker.postMessage(out, js.Array(out).asInstanceOf[js.UndefOr[js.Array[dom.raw.Transferable]]])
}
}
开发者ID:suzaku-io,项目名称:suzaku,代码行数:45,代码来源:WebWorkerTransport.scala
示例3: WebDemoUIEntry
//设置package包名称以及导入依赖的类
package webdemo
import suzaku.platform.web.{WebWorkerTransport, WorkerClientTransport}
import org.scalajs.dom
import org.scalajs.dom.raw.Worker
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
@JSExportTopLevel("WebDemoUIEntry")
object WebDemoUIEntry {
var transport: WebWorkerTransport = _
@JSExport
def entry(workerScript: String): Unit = {
// create the worker to run our application in
val worker = new Worker(workerScript)
// create the transport
transport = new WorkerClientTransport(worker)
// listen to messages from worker
worker.onmessage = onMessage _
new WebDemoUI(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
开发者ID:suzaku-io,项目名称:suzaku,代码行数:51,代码来源:WebDemoUIEntry.scala
示例4: WebDemoAppEntry
//设置package包名称以及导入依赖的类
package webdemo
import suzaku.platform.web.{WebWorkerTransport, WorkerTransport}
import org.scalajs.dom
import org.scalajs.dom.raw.DedicatedWorkerGlobalScope
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
@JSExportTopLevel("WebDemoAppEntry")
object WebDemoAppEntry {
import DedicatedWorkerGlobalScope.self
var transport: WebWorkerTransport = _
@JSExport
def entry(): Unit = {
// create transport
transport = new WorkerTransport(self)
// receive WebWorker messages
self.onmessage = onMessage _
// create the actual application
val app = new WebDemoApp(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
开发者ID:suzaku-io,项目名称:suzaku,代码行数:49,代码来源:WebDemoAppEntry.scala
示例5: PerfUIEntry
//设置package包名称以及导入依赖的类
package perftest
import org.scalajs.dom
import org.scalajs.dom.raw.Worker
import suzaku.platform.web.{WebWorkerTransport, WorkerClientTransport}
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.ArrayBuffer
@JSExportTopLevel("PerfUIEntry")
object PerfUIEntry {
var transport: WebWorkerTransport = _
@JSExport
def entry(workerScript: String): Unit = {
// create the worker to run our application in
val worker = new Worker(workerScript)
// create the transport
transport = new WorkerClientTransport(worker)
// listen to messages from worker
worker.onmessage = onMessage _
new PerfUI(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
开发者ID:suzaku-io,项目名称:suzaku,代码行数:51,代码来源:PerfUIEntry.scala
示例6: PerfAppEntry
//设置package包名称以及导入依赖的类
package perftest
import org.scalajs.dom
import org.scalajs.dom.raw.DedicatedWorkerGlobalScope
import suzaku.platform.web.{WebWorkerTransport, WorkerTransport}
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.ArrayBuffer
@JSExportTopLevel("PerfAppEntry")
object PerfAppEntry {
import DedicatedWorkerGlobalScope.self
var transport: WebWorkerTransport = _
@JSExport
def entry(): Unit = {
// create transport
transport = new WorkerTransport(self)
// receive WebWorker messages
self.onmessage = onMessage _
// create the actual application
val app = new PerfApp(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
开发者ID:suzaku-io,项目名称:suzaku,代码行数:49,代码来源:PerfAppEntry.scala
示例7: Converters
//设置package包名称以及导入依赖的类
package fr.hmil.roshttp
import java.nio.ByteBuffer
import fr.hmil.roshttp.node.buffer.Buffer
import scala.scalajs.js
import scala.scalajs.js.typedarray.{ArrayBuffer, Int8Array, TypedArrayBuffer, Uint8Array}
import scala.scalajs.js.JSConverters._
import js.typedarray.TypedArrayBufferOps._
private object Converters {
def byteArrayToUint8Array(arr: Array[Byte]): Uint8Array = {
js.Dynamic.newInstance(js.Dynamic.global.Uint8Array)(arr.toJSArray).asInstanceOf[Uint8Array]
}
def byteBufferToNodeBuffer(buffer: ByteBuffer): Buffer = {
if (buffer.isDirect) {
js.Dynamic.newInstance(js.Dynamic.global.Buffer)(buffer.arrayBuffer).asInstanceOf[Buffer]
} else if (buffer.hasArray) {
js.Dynamic.newInstance(js.Dynamic.global.Buffer)(byteArrayToUint8Array(buffer.array())).asInstanceOf[Buffer]
} else {
val arr = new Int8Array(buffer.limit)
var i = 0
while (i < arr.length) {
arr(i) = buffer.get(i)
i += 1
}
js.Dynamic.newInstance(js.Dynamic.global.Buffer)(arr).asInstanceOf[Buffer]
}
}
def nodeBufferToByteBuffer(buffer: Buffer): ByteBuffer = {
TypedArrayBuffer.wrap(buffer.asInstanceOf[ArrayBuffer])
}
def arrayBufferToByteBuffer(buffer: ArrayBuffer): ByteBuffer = {
TypedArrayBuffer.wrap(buffer)
}
}
开发者ID:hmil,项目名称:RosHTTP,代码行数:41,代码来源:Converters.scala
示例8: Buffer
//设置package包名称以及导入依赖的类
package sharednodejsapis
import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.typedarray.ArrayBuffer
@js.native
@JSGlobal
abstract class Buffer extends js.typedarray.Uint8Array(0) {
def toString(encoding: String = "utf8", start: Int = 0, end: Int = this.length): String = js.native
}
@js.native
@JSGlobal
object Buffer extends js.Object {
def from(s: String, encoding: String = "utf8"): Buffer = js.native
def from(msg: ArrayBuffer): Buffer = js.native
}
开发者ID:sherpal,项目名称:oh-hell-card-game,代码行数:20,代码来源:Buffer.scala
示例9: NativeUtils
//设置package包名称以及导入依赖的类
package akkaviz.frontend
import scala.scalajs.js
import scala.scalajs.js.typedarray.{ArrayBufferView, Uint8Array, ArrayBuffer}
object NativeUtils {
val encoder = new TextEncoder("utf-8")
val decoder = new TextDecoder("utf-8")
def ab2str(ab: ArrayBuffer): String = {
decoder.decode(new Uint8Array(ab))
}
def str2ab(str: String): Uint8Array = {
encoder.encode(str)
}
}
@js.native
class TextEncoder(utfLabel: js.UndefOr[String]) extends js.Object {
def encode(buffer: String): Uint8Array = js.native
}
@js.native
class TextDecoder(utfLabel: js.UndefOr[String]) extends js.Object {
def decode(buffer: Uint8Array): String = js.native
}
开发者ID:blstream,项目名称:akka-viz,代码行数:30,代码来源:NativeUtils.scala
示例10: BinaryAjax
//设置package包名称以及导入依赖的类
package io.plasmap.js
import java.nio.ByteBuffer
import io.plasmap.querymodel.PMQuery
import org.scalajs.dom
import org.scalajs.dom.ext.AjaxException
import scala.scalajs.js.typedarray.TypedArrayBufferOps._
import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
import scala.concurrent.Promise
object BinaryAjax {
//Binary data support for Scala.js DOM 0.6.2
def post(url:String,
data:ByteBuffer,
timeout:Int = 0,
headers:Map[String, String] = Map.empty,
withCredentials: Boolean = false,
responseType: String = "" ) = {
val req = new dom.XMLHttpRequest()
val promise = Promise[dom.XMLHttpRequest]()
req.onreadystatechange = { (e:dom.Event) ?
if (req.readyState == 4) {
if ((req.status >= 200 && req.status < 300) || req.status == 304)
promise success req
else
promise failure AjaxException(req)
}
}
req.open("POST", url)
req.responseType = responseType
req.timeout = timeout
req.withCredentials = withCredentials
for((header, value) ? headers) req.setRequestHeader(header, value)
req.send(data.typedArray())
promise.future
}
}
开发者ID:plasmap,项目名称:plasmap,代码行数:41,代码来源:BinaryAjax.scala
示例11: assetsEndpoint
//设置package包名称以及导入依赖的类
package endpoints.xhr
import endpoints.algebra
import org.scalajs.dom.XMLHttpRequest
import scala.scalajs.js
import scala.scalajs.js.typedarray.ArrayBuffer
def assetsEndpoint(url: Url[AssetPath]): Endpoint[AssetRequest, AssetResponse] =
endpoint(arrayBufferGet(url), arrayBufferResponse)
private def arrayBufferGet(url: Url[AssetPath]): Request[AssetRequest] =
(assetRequest: AssetRequest) => {
val xhr = new XMLHttpRequest
xhr.open("GET", url.encode(assetRequest))
xhr.responseType = "arraybuffer"
(xhr, None)
}
private def arrayBufferResponse: Response[ArrayBuffer] =
(xhr: XMLHttpRequest) => {
if (xhr.status < 300) {
try {
Right(xhr.response.asInstanceOf[ArrayBuffer])
} catch {
case exn: Exception => Left(exn)
}
} else Left(new Exception("Resource not found"))
}
}
开发者ID:julienrf,项目名称:endpoints,代码行数:33,代码来源:Assets.scala
注:本文中的scala.scalajs.js.typedarray.ArrayBuffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论