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

widebase.stream.codec.rq.ConsumerEncoder.scala Maven / Gradle / Ivy

There is a newer version: 0.3.3
Show newest version
package widebase.stream.codec.rq

import org.jboss.netty.buffer. { ChannelBuffer, ChannelBuffers }
import org.jboss.netty.channel.Channel
import org.jboss.netty.channel.ChannelHandlerContext

import widebase.stream.codec. { MessageTypeEncoder, RequestEncoder }

/** Encode consumer message.
 *
 * @author myst3r10n
 */
class ConsumerEncoder extends RequestEncoder with MessageTypeEncoder {

  @throws(classOf[Exception])
  override def encode(
    ctx: ChannelHandlerContext,
    channel: Channel,
    msg: Object): Object = {

    val buffer = ChannelBuffers.dynamicBuffer

    msg match {

      case msg: SubscribeMessage =>
        writeId(buffer, MessageType.SubscribeMessage.id)
        writeString(buffer, msg.name)
        writeString(buffer, msg.selector)

      case _ => return super.encode(ctx, channel, msg)

    }

    buffer

  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy