• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala ByteOrder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中java.nio.ByteOrder的典型用法代码示例。如果您正苦于以下问题:Scala ByteOrder类的具体用法?Scala ByteOrder怎么用?Scala ByteOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ByteOrder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: stringToNTBytes

//设置package包名称以及导入依赖的类
package com.init6.coders.binary

import java.nio.ByteOrder

import akka.util.ByteString


trait BinaryPacket {

  implicit val byteOrder = ByteOrder.LITTLE_ENDIAN

  val PACKET_HEADER: Byte = 0xFF.toByte
  val PACKET_HEADER_LENGTH: Short = 4

  val PACKET_ID: Byte

  implicit def stringToNTBytes(string: String): Array[Byte] = {
    Array.newBuilder[Byte]
      .++=(string.map(_.toByte))
      .+=(0)
      .result()
  }

  def build(data: ByteString) = {
    ByteString.newBuilder
      .putByte(PACKET_HEADER)
      .putByte(PACKET_ID)
      .putShort(data.length + PACKET_HEADER_LENGTH)
      .append(data)
      .result()
  }
} 
开发者ID:fjaros,项目名称:init6,代码行数:33,代码来源:BinaryPacket.scala


示例2: sport

//设置package包名称以及导入依赖的类
package edu.uw.at.iroberts.wirefugue.protocol.overlay

import java.nio.ByteOrder

import edu.uw.at.iroberts.wirefugue.pcap.ByteSeqOps._


trait UDPHeader {
  def sport: Short
  def dport: Short
  def length: Int
  def checksum: Short
}

case class UDPDatagram(bytes: IndexedSeq[Byte]) extends UDPHeader {
  implicit val byteOrder = ByteOrder.BIG_ENDIAN
  def sport: Short = bytes.slice(0, 2).getInt16
  def dport: Short = bytes.slice(2, 4).getInt16
  def length: Int = bytes.slice(4, 6).getUInt16
  def checksum: Short = bytes.slice(6, 8).getInt16
} 
开发者ID:robertson-tech,项目名称:wirefugue,代码行数:22,代码来源:UDPDatagram.scala


示例3: ConfirmStep

//设置package包名称以及导入依赖的类
package com.spooky.inbound.step

import com.spooky.inbound.OutStep
import com.spooky.inbound.InStep
import com.spooky.inbound.Base
import com.spooky.inbound.Reply
import spooky.util.ByteString
import com.spooky.inbound.OutStep
import com.spooky.cipher.RC4ReadCipher
import com.spooky.cipher.RC4WriteCipher
import java.nio.ByteBuffer
import java.nio.ByteOrder
import akka.util.FakeBStrings
import com.spooky.inbound.CryptoProvider
import com.spooky.cipher.WriteCipher
import com.spooky.cipher.ReadCipher
import com.spooky.inbound.RC4
import com.spooky.inbound.Plain
import com.spooky.cipher.WritePlain
import com.spooky.cipher.ReadPlain
import com.spooky.cipher.MSEKeyPair

class ConfirmStep(readCipher: RC4ReadCipher, writeCipher: RC4WriteCipher, cryptoProvider: CryptoProvider, data: Option[ByteString]) extends Base with OutStep {

  def step(reply: Reply): InStep = {

    val padding = randomPadding()
    val writeBuffer = ByteBuffer.allocate(VC.length + 4 + 2 + padding.length).order(ByteOrder.BIG_ENDIAN);

    writeBuffer.put(writeCipher.update(VC));
    writeBuffer.put(writeCipher.update(Array[Byte](0, 0, 0, CRYPTO_RC4)))
    writeBuffer.put(writeCipher.update(Array[Byte]((padding.length >> 8).asInstanceOf[Byte], padding.length.asInstanceOf[Byte])))
    if (writeBuffer.remaining() != padding.length) {
      throw new RuntimeException("not correct");
    }
    writeBuffer.put(writeCipher.update(padding));

    writeBuffer.flip();

    reply.reply(FakeBStrings(writeBuffer))

    val (chosenWriteCipher, chosenReadCipher) = choose(cryptoProvider, writeCipher, readCipher)
    new DoneStep(MSEKeyPair(chosenWriteCipher, chosenReadCipher), data)
  }

  private def choose(cryptoProvider: CryptoProvider, writeCipher: RC4WriteCipher, readCipher: RC4ReadCipher): Tuple2[WriteCipher, ReadCipher] = cryptoProvider match {
    case RC4   => (writeCipher, readCipher)
    case Plain => (WritePlain, ReadPlain)
    case c     => throw new RuntimeException(s"Unknown crypto select: $c")
  }

} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:53,代码来源:ConfirmStep.scala


示例4: SendPublicKeyStep

//设置package包名称以及导入依赖的类
package com.spooky.inbound.step

import com.spooky.inbound.Base
import com.spooky.inbound.InStep
import com.spooky.inbound.OutStep
import com.spooky.inbound.Reply
import spooky.util.ByteString
import com.spooky.bittorrent.InfoHash
import com.spooky.inbound.LocalPublicKey
import com.spooky.inbound.RemotePublicKey
import com.spooky.inbound.SecretKey
import java.nio.ByteOrder
import java.nio.ByteBuffer
import akka.util.FakeBStrings

class SendPublicKeyStep(infoHashes: List[InfoHash], publicKey: LocalPublicKey, remotePublicKey: RemotePublicKey, secretKey: SecretKey) extends Base with OutStep {
  def step(reply: Reply): ReceiveInfoStep = {
    val padding = randomPadding()
    val rawPublicKey = publicKey.raw

    println(rawPublicKey.length)
//    assert(rawPublicKey.length == 96)

    val buffer = ByteBuffer.allocate(rawPublicKey.length + padding.length).order(ByteOrder.BIG_ENDIAN)
    buffer.put(rawPublicKey)
    buffer.put(padding)

    assert(!buffer.hasRemaining)

    reply.reply(FakeBStrings(buffer.flip().asInstanceOf[ByteBuffer]))

    new ReceiveInfoStep(infoHashes, publicKey, remotePublicKey, secretKey)
  }

} 
开发者ID:zpooky,项目名称:bittorrent,代码行数:36,代码来源:SendPublicKeyStep.scala


示例5: CommonBuffer

//设置package包名称以及导入依赖的类
package knot.data.buffers

import java.nio.ByteOrder


object CommonBuffer {
  def allocate(size: Int, byteOrder: ByteOrder): UnsafeArrayBuffer = {
    require(size >= 0, s"size must be >= 0 (size=$size)")
    create(Array.ofDim[Byte](size), 0, size, byteOrder)
  }

  def wrap(bytes: Array[Byte], byteOrder: ByteOrder): UnsafeArrayBuffer = {
    require(bytes ne null, "bytes must be not null")
    create(bytes, 0, bytes.length, byteOrder)
  }

  private def create(buffer: Array[Byte], offset: Int, length: Int, byteOrder: ByteOrder): UnsafeArrayBuffer = {
    byteOrder match {
      case ByteOrder.LITTLE_ENDIAN =>
        new UnsafeArrayBuffer(buffer, offset, length)
      case _ =>
        throw new IllegalArgumentException()
    }
  }
} 
开发者ID:defvar,项目名称:knot,代码行数:26,代码来源:CommonBuffer.scala


示例6: MsgPackBufferBench

//设置package包名称以及导入依赖的类
package knot.msgpack

import java.nio.ByteOrder
import java.util.concurrent.TimeUnit

import knot.data.buffers.CommonBuffer
import org.msgpack.core.buffer.MessageBuffer
import org.openjdk.jmh.annotations._

@State(Scope.Benchmark)
@Measurement(timeUnit = TimeUnit.MILLISECONDS)
class MsgPackBufferBench {

  val org = MessageBuffer.allocate(8192)
  val knot = CommonBuffer.allocate(8192, ByteOrder.nativeOrder())

  @Benchmark
  def knot_1_1000() = {
    for (i <- (0 until 1000)) {
      knot.putInt(i, i)
    }
  }

  @Benchmark
  def org_1000() = {
    for (i <- (0 until 1000)) {
      org.putInt(i, i)
    }
  }

} 
开发者ID:defvar,项目名称:knot,代码行数:32,代码来源:MsgPackBufferBench.scala


示例7: PacketReader

//设置package包名称以及导入依赖的类
package handlers.packets

import java.nio.{ByteBuffer, ByteOrder}


class PacketReader(val data: Array[Byte]) extends Packets {

  var cursor: Int = 0

  def skip(a: Int): Unit = {
    cursor += a
  }

  def readByte(): Byte = {
    val res: Byte = data(cursor)
    cursor += byteSize
    res
  }

  def readShort(endian: ByteOrder = ByteOrder.BIG_ENDIAN): Short = {
    val res: Short = ByteBuffer.wrap(data.slice(cursor, cursor+shortSize)).order(endian).getShort
    cursor += shortSize
    res
  }

  def readInt(endian: ByteOrder = ByteOrder.BIG_ENDIAN): Int = {
    val res: Int = ByteBuffer.wrap(data.slice(cursor, cursor+intSize)).order(endian).getInt
    cursor += intSize
    res
  }

  def readString(size: Int): String = {
    val res: String = PacketsUtils.printableString(new String(data.slice(cursor, cursor+size)))
    cursor += size
    res
  }

} 
开发者ID:franblas,项目名称:NAOC,代码行数:39,代码来源:PacketReader.scala


示例8: UpdatePoints

//设置package包名称以及导入依赖的类
package handlers.server

import java.nio.ByteOrder

import handlers.packets.PacketWriter

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future


class UpdatePoints {
  def process(): Future[Array[Byte]] = {
    val realmPoints = 0x00 //TODO
    val levelPermill = 0x00 //TODO
    val skillSpecialityPoints = 0x00 //TODO
    val bountyPoints = 0x00 //TODO
    val realmSpecialityPoints = 0x00 //TODO
    val championLevelPermill = 0x00 //TODO
    val experience = 0x00 //TODO
    val experienceForNextLevel = 0x32 //TODO
    val champExperience = 0x00
    val champExperienceForNextLevel = 0x00

    val writer = new PacketWriter(0x91)
    writer.writeInt(realmPoints.toInt)
    writer.writeShort(levelPermill.toShort)
    writer.writeShort(skillSpecialityPoints.toShort)
    writer.writeInt(bountyPoints.toInt)
    writer.writeShort(realmSpecialityPoints.toShort)
    writer.writeShort(championLevelPermill.toShort)
    writer.writeLong(experience.toLong, ByteOrder.LITTLE_ENDIAN)
    writer.writeLong(experienceForNextLevel.toLong, ByteOrder.LITTLE_ENDIAN)
    writer.writeLong(champExperience.toLong, ByteOrder.LITTLE_ENDIAN)
    writer.writeLong(champExperienceForNextLevel.toLong, ByteOrder.LITTLE_ENDIAN)
    Future {
      writer.getFinalPacket()
    }
  }
} 
开发者ID:franblas,项目名称:NAOC,代码行数:40,代码来源:UpdatePoints.scala


示例9: scalar

//设置package包名称以及导入依赖的类
package cassandra.decoder

import akka.util.ByteIterator

import java.nio.ByteOrder

import cassandra.BigEndian
import cassandra.protocol._

trait DefaultDecoders {
  def scalar[A](bytesSize: Int)(extract: ByteIterator => A)(implicit byteOrder: ByteOrder) = Decoder[A] { bs =>
    if(bs.length >= bytesSize) {
      val (payload, remaining) = bs.splitAt(bytesSize)
      Consumed(extract(payload.iterator), remaining)
    }
    else NotEnough
  }

  def double(implicit byteOrder: ByteOrder) = scalar[Double](8)(_.getDouble)
  def float(implicit byteOrder: ByteOrder) = scalar[Float](4)(_.getFloat)
  def long(implicit byteOrder: ByteOrder) = scalar[Long](8)(_.getLong)
  def int(implicit byteOrder: ByteOrder) = scalar[Int](4)(_.getInt)
  def short(implicit byteOrder: ByteOrder) = scalar[Short](2)(_.getShort)
  def byte(implicit byteOrder: ByteOrder) = scalar[Byte](1)(_.getByte)

  def list[A](size: Int)(A: Decoder[A]) = Decoder[List[A]] { bytes =>
    val decodedAS = (0 until size).foldLeft(DecoderResult.consumed(List.empty[A], bytes)) { (prev, _) =>
      prev match {
        case NotEnough => NotEnough
        case Consumed(as, bytes) =>
          A.decode(bytes) match {
            case Consumed(a, remaining) => Consumed(a :: as, remaining)
            case NotEnough => NotEnough
          }
      }
    }

    decodedAS match {
      case Consumed(as, remaining) => Consumed(as.reverse, remaining)
      case NotEnough => NotEnough
    }
  }

  def tuple[A, B](A: Decoder[A], B: Decoder[B]): Decoder[(A, B)] = for {
    a <- A
    b <- B
  } yield (a, b)

  def tuple[A, B, C](A: Decoder[A], B: Decoder[B], C: Decoder[C]): Decoder[(A, B, C)] = for {
    a <- A
    b <- B
    c <- C
  } yield (a, b, c)
} 
开发者ID:ybr,项目名称:cassandra-scala,代码行数:55,代码来源:DefaultDecoders.scala


示例10: BinaryUtil

//设置package包名称以及导入依赖的类
package zeroformatter

import java.nio.{ByteBuffer, ByteOrder}

private[zeroformatter] object BinaryUtil {

  def wrapByteArray(bytes: Array[Byte]): ByteBuffer =
    ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)

  def allocate(capacity: Int): ByteBuffer =
    ByteBuffer.allocate(capacity).order(ByteOrder.LITTLE_ENDIAN)

  def resize(array: Array[Byte], newSize: Int): Array[Byte] = {
    if(array.length != newSize) {
      val array2 = new Array[Byte](newSize)
      val l = array.length
      array.copyToArray(array2, 0, if(l > newSize) newSize else l)
      array2
    }
    else array
  }

  def ensureCapacity(bytes: Array[Byte], offset: Int, appendLength: Int): Array[Byte] = {
    val newLength = offset + appendLength

    val current = bytes.length
    if(newLength > current) {
      val num =
        if(newLength < 256) 256
        else if(newLength < current * 2) current * 2
        else newLength
      resize(bytes, num)
    }
    else bytes
  }
} 
开发者ID:pocketberserker,项目名称:scala-zero-formatter,代码行数:37,代码来源:BinaryUtil.scala


示例11: DataBuffer

//设置package包名称以及导入依赖的类
package com.esri.gdb

import java.nio.{ByteBuffer, ByteOrder}

import org.apache.hadoop.fs.FSDataInputStream


class DataBuffer(dataInput: FSDataInputStream) extends Serializable {

  private var bytes = new Array[Byte](1024)
  private var byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)

  def readBytes(length: Int) = {
    if (length > bytes.length) {
      bytes = new Array[Byte](length)
      byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)
    }
    else {
      byteBuffer.clear
    }
    dataInput.readFully(bytes, 0, length)
    byteBuffer
  }

  def seek(position: Long) = {
    dataInput.seek(position)
    this
  }

  def close() {
    dataInput.close()
  }
}

object DataBuffer {
  def apply(dataInput: FSDataInputStream) = {
    new DataBuffer(dataInput)
  }
} 
开发者ID:mraad,项目名称:spark-gdb,代码行数:40,代码来源:DataBuffer.scala


示例12: ObjectRenderer

//设置package包名称以及导入依赖的类
package com.dafttech.jasper.render

import java.nio.{ByteBuffer, ByteOrder}

import com.dafttech.jasper.scene.{Entity, RenderingEntity, RenderingGroup}
import com.dafttech.jasper.util.Vertex
import org.lwjgl.opengl.GL11._
import org.lwjgl.opengl.GL12
import org.lwjgl.opengl.GL12._
import org.lwjgl.opengl.GL15._

object ObjectRenderer {
  val objMatBuffer = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer()
  val groupMatBuffer = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer()

  val Triangles = new ObjectRenderer[RenderingEntity] {
    override def render(input: RenderingEntity): Unit = {
      groupMatBuffer.rewind()
      objMatBuffer.rewind()
      glLoadMatrixf(groupMatBuffer)
      glMultMatrixf(input.transformation.get(objMatBuffer))

      glDrawElements(GL_TRIANGLES, input.getTesselator.getIdxCount(input), GL_UNSIGNED_INT, input.vbLoc.indexPosition * 4)
    }
  }

  val RenderingGroup = new ObjectRenderer[RenderingGroup] {
    override def render(input: RenderingGroup): Unit = {
      input.transformation.get(groupMatBuffer)

      for (e <- input.childs) {
        e.getRenderer.render(e)
      }
    }
  }
}

abstract class ObjectRenderer[T <: Entity] {
  def render(input: T): Unit
} 
开发者ID:DaftTech,项目名称:JasperGE,代码行数:41,代码来源:ObjectRenderer.scala


示例13: Colour

//设置package包名称以及导入依赖的类
package io.cosmicteapot


import java.nio.ByteOrder



object Colour {
  type ColourI = Int

  def r(c:ColourI) : Int = c & 0xff
  def g(c:ColourI) : Int = (c >>> 8) & 0xff
  def b(c:ColourI) : Int = (c >>> 16) & 0xff
  def a(c:ColourI) : Int = (c >>> 24) & 0xff

  def rf(c:ColourI) : Float = r(c).asInstanceOf[Float] / 255f
  def gf(c:ColourI) : Float = g(c).asInstanceOf[Float] / 255f
  def bf(c:ColourI) : Float = b(c).asInstanceOf[Float] / 255f
  def af(c:ColourI) : Float = a(c).asInstanceOf[Float] / 255f

  val maskOffOneBit = ~ Integer.parseInt("00000001000000000000000000000000", 2)

  def littleEndian : Boolean = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN
  def colourI(sample:Array[Int]) : ColourI = colourI(sample(0), sample(1), sample(2), sample(3))
  def colourI(r:Int, g:Int, b:Int, a:Int) : ColourI = {
    val ur = clamp(r, 0, 255)
    val ug = clamp(g, 0, 255)
    val ub = clamp(b, 0, 255)
    val ua = clamp(a, 0, 255)
    if(littleEndian) {
      //      println("we are little endian")
      (ua << 24 | ub << 16 | ug << 8 | ur) & maskOffOneBit // mask off one bit just
    } else {
      //      println("we are not little endian!")
      ur << 24 | ug << 16 | ub << 8 | ua
    }
  }
  def clamp(n:Int, a:Int, b:Int) : Int = {
    if(n < a) a else if(n > b ) b else n
  }

  val white = colourI(255,255,255,255)
  val black = colourI(0, 0, 0, 255)
  val transWhite = colourI(255,255,255,0)
  val transBlack = colourI(0, 0, 0, 0)
} 
开发者ID:MichaelShaw,项目名称:gridme,代码行数:47,代码来源:Colour.scala


示例14: ClusterSecrets

//设置package包名称以及导入依赖的类
package com.vivint.ceph.model

import akka.util.ByteString
import java.security.SecureRandom
import java.util.UUID
import java.nio.{ByteOrder,ByteBuffer}
case class ClusterSecrets(
  fsid: UUID,
  adminRing: ByteString,
  monRing: ByteString,
  mdsRing: ByteString,
  osdRing: ByteString,
  rgwRing: ByteString)

object ClusterSecrets {
  lazy val random = new SecureRandom()
  val KeySize = 16
  def generateKey = {
    // 0000000: 0100 3c64 f357 3dfe bd34 1000 2a00 93c7  ..<d.W=..4..*...
    // 0000010: 057f 89b6 c0b0 4682 6d22 33f1            ......F.m"3.
    val b = ByteBuffer.allocate(2 + 8 + 2 + KeySize)
    b.order(ByteOrder.LITTLE_ENDIAN)
    b.putShort(1)
    b.putInt((System.currentTimeMillis / 1000).toInt)
    b.putInt((System.nanoTime).toInt)
    b.putShort(16)
    val bytes = Array.fill[Byte](KeySize)(0)
    random.nextBytes(bytes)
    b.put(bytes)
    ByteString(b.array)
  }

  def generate: ClusterSecrets = {
    ClusterSecrets(
      UUID.randomUUID,
      generateKey,
      generateKey,
      generateKey,
      generateKey,
      generateKey)
  }
} 
开发者ID:vivint-smarthome,项目名称:ceph-on-mesos,代码行数:43,代码来源:ClusterSecrets.scala


示例15: Buffer

//设置package包名称以及导入依赖的类
package org.hammerlab.io

import java.nio.ByteOrder.LITTLE_ENDIAN
import java.nio.{ ByteBuffer, ByteOrder }

object Buffer {
  
  def apply(capacity: Int)(
      implicit order: ByteOrder = LITTLE_ENDIAN
  ): ByteBuffer =
    ByteBuffer
      .allocate(capacity)
      .order(LITTLE_ENDIAN)

  def apply(bytes: Array[Byte]): ByteBuffer = ByteBuffer.wrap(bytes)

  def apply(bytes: Array[Byte], offset: Int, length: Int): ByteBuffer = {
    val buffer = apply(bytes)
    buffer.position(offset)
    buffer.limit(offset + length)
    buffer
  }
} 
开发者ID:hammerlab,项目名称:io-utils,代码行数:24,代码来源:Buffer.scala



注:本文中的java.nio.ByteOrder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala BigInteger类代码示例发布时间:2022-05-23
下一篇:
Scala GeneratorDrivenPropertyChecks类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap