本文整理汇总了Scala中io.netty.handler.codec.bytes.ByteArrayEncoder类的典型用法代码示例。如果您正苦于以下问题:Scala ByteArrayEncoder类的具体用法?Scala ByteArrayEncoder怎么用?Scala ByteArrayEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ByteArrayEncoder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ServerInitializer
//设置package包名称以及导入依赖的类
package com.bwsw.tstreamstransactionserver.netty.server
import com.bwsw.tstreamstransactionserver.netty.Message
import com.bwsw.tstreamstransactionserver.options.ServerOptions.TransportOptions
import io.netty.buffer.ByteBuf
import io.netty.channel.socket.SocketChannel
import io.netty.channel.{ChannelInitializer, SimpleChannelInboundHandler}
import io.netty.handler.codec.LengthFieldBasedFrameDecoder
import io.netty.handler.codec.bytes.ByteArrayEncoder
class ServerInitializer(serverHandler: => SimpleChannelInboundHandler[ByteBuf]) extends ChannelInitializer[SocketChannel] {
override def initChannel(ch: SocketChannel): Unit = {
ch.pipeline()
.addLast(new ByteArrayEncoder())
.addLast(new LengthFieldBasedFrameDecoder(
Int.MaxValue,
//packageTransmissionOpts.maxDataPackageSize max packageTransmissionOpts.maxMetadataPackageSize,
Message.headerFieldSize,
Message.lengthFieldSize)
)
.addLast(serverHandler)
}
}
示例2: ClientInitializer
//设置package包名称以及导入依赖的类
package com.bwsw.tstreamstransactionserver.netty.client
import java.util.concurrent.ConcurrentHashMap
import com.twitter.scrooge.ThriftStruct
import com.bwsw.tstreamstransactionserver.netty.Message
import io.netty.channel.ChannelInitializer
import io.netty.channel.socket.SocketChannel
import io.netty.handler.codec.LengthFieldBasedFrameDecoder
import io.netty.handler.codec.bytes.ByteArrayEncoder
import scala.concurrent.{ExecutionContext, Promise => ScalaPromise}
class ClientInitializer(reqIdToRep: ConcurrentHashMap[Long, ScalaPromise[ThriftStruct]], client: Client, context: ExecutionContext) extends ChannelInitializer[SocketChannel] {
override def initChannel(ch: SocketChannel): Unit = {
ch.pipeline()
.addLast(new ByteArrayEncoder())
.addLast(new LengthFieldBasedFrameDecoder(
Int.MaxValue,
Message.headerFieldSize,
Message.lengthFieldSize)
)
.addLast(new ClientHandler(reqIdToRep, client, context))
}
}