本文整理汇总了Scala中io.netty.handler.codec.LengthFieldBasedFrameDecoder类的典型用法代码示例。如果您正苦于以下问题:Scala LengthFieldBasedFrameDecoder类的具体用法?Scala LengthFieldBasedFrameDecoder怎么用?Scala LengthFieldBasedFrameDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LengthFieldBasedFrameDecoder类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Netty4Framer
//设置package包名称以及导入依赖的类
package com.twitter.finagle.mux.transport
import com.twitter.finagle.netty4.DirectToHeapInboundHandlerName
import com.twitter.finagle.netty4.channel.DirectToHeapInboundHandler
import com.twitter.finagle.netty4.codec.BufCodec
import io.netty.channel.ChannelPipeline
import io.netty.handler.codec.{LengthFieldPrepender, LengthFieldBasedFrameDecoder}
private[finagle] object Netty4Framer extends (ChannelPipeline => Unit) {
private val maxFrameLength = 0x7FFFFFFF
private val lengthFieldOffset = 0
private val lengthFieldLength = 4
private val lengthAdjustment = 0
private val initialBytesToStrip = 4
def apply(pipeline: ChannelPipeline): Unit = {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(
maxFrameLength,
lengthFieldOffset,
lengthFieldLength,
lengthAdjustment,
initialBytesToStrip))
pipeline.addLast("frameEncoder", new LengthFieldPrepender(lengthFieldLength))
pipeline.addLast(DirectToHeapInboundHandlerName, DirectToHeapInboundHandler)
pipeline.addLast("bufCodec", new BufCodec)
}
}
示例2: ThriftFrameCodec
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift.transport.netty4
import io.netty.channel.{ChannelHandler, CombinedChannelDuplexHandler}
import io.netty.handler.codec.{LengthFieldBasedFrameDecoder, LengthFieldPrepender}
private[netty4] object ThriftFrameCodec {
private val maxFrameLength = Integer.MAX_VALUE // 0x7FFFFFFF
private val lengthFieldOffset = 0
private val lengthFieldLength = 4
private val lengthAdjustment = 0
private val initialBytesToStrip = 4
def apply(): ChannelHandler = {
val encoder = new LengthFieldPrepender(ThriftFrameCodec.lengthFieldLength)
val decoder = new LengthFieldBasedFrameDecoder(
ThriftFrameCodec.maxFrameLength,
ThriftFrameCodec.lengthFieldOffset,
ThriftFrameCodec.lengthFieldLength,
ThriftFrameCodec.lengthAdjustment,
ThriftFrameCodec.initialBytesToStrip)
new CombinedChannelDuplexHandler(decoder, encoder)
}
}
示例3: LegacyChannelInitializer
//设置package包名称以及导入依赖的类
package com.wavesplatform.it.network.client
import com.wavesplatform.network.{HandshakeDecoder, HandshakeHandler, HandshakeTimeoutHandler, LegacyFrameCodec}
import io.netty.channel.ChannelInitializer
import io.netty.channel.socket.SocketChannel
import io.netty.handler.codec.{LengthFieldBasedFrameDecoder, LengthFieldPrepender}
import scala.concurrent.duration._
class LegacyChannelInitializer(handshakeHandler: HandshakeHandler) extends ChannelInitializer[SocketChannel] {
override def initChannel(ch: SocketChannel): Unit =
ch.pipeline()
.addLast(
new HandshakeDecoder,
new HandshakeTimeoutHandler(30.seconds),
handshakeHandler,
new LengthFieldPrepender(4),
new LengthFieldBasedFrameDecoder(1024*1024, 0, 4, 0, 4),
new LegacyFrameCodec(NopPeerDatabase))
}
示例4: 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)
}
}
示例5: 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))
}
}
示例6: LegacyChannelInitializer
//设置package包名称以及导入依赖的类
package com.wavesplatform.it.network.client
import com.wavesplatform.network.{HandshakeDecoder, HandshakeHandler, HandshakeTimeoutHandler, LegacyFrameCodec}
import io.netty.channel.ChannelInitializer
import io.netty.channel.socket.SocketChannel
import io.netty.handler.codec.{LengthFieldBasedFrameDecoder, LengthFieldPrepender}
import scala.concurrent.duration._
class LegacyChannelInitializer(handshakeHandler: HandshakeHandler) extends ChannelInitializer[SocketChannel] {
override def initChannel(ch: SocketChannel): Unit =
ch.pipeline()
.addLast(
new HandshakeDecoder,
new HandshakeTimeoutHandler(30.seconds),
handshakeHandler,
new LengthFieldPrepender(4),
new LengthFieldBasedFrameDecoder(1024*1024, 0, 4, 0, 4),
new LegacyFrameCodec)
}