All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twitter.finagle.thrift.transport.netty4.ThriftFrameCodec.scala Maven / Gradle / Ivy

There is a newer version: 24.2.0
Show newest version
package com.twitter.finagle.thrift.transport.netty4

import io.netty.channel.{ChannelHandler, CombinedChannelDuplexHandler}
import io.netty.handler.codec.{LengthFieldBasedFrameDecoder, LengthFieldPrepender}

/**
 * An implementation of a Thrift framer using netty4 primitives.
 */
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)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy