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

sss.openstar.message.serialize.PagedMsgSerializer.scala Maven / Gradle / Ivy

package sss.openstar.message.serialize

import sss.ancillary.Serialize._
import sss.ancillary.ShortSessionKey._
import sss.openstar.message._

/**
  * Created by alan on 6/8/16.
  */
object PagedMsgSerializer extends Serializer[PagedMessage] {

  def toBytes(o: PagedMessage): Array[Byte] =

    ByteArraySerializer(o.sessKey.toBytes) ++
    LongSerializer(o.mostRecentUniqueIncreasing) ++
      ByteArraySerializer(o.msg.toBytes)
        .toBytes

  def fromBytes(bs: Array[Byte]): PagedMessage = {
    PagedMessage.tupled(
      bs.extract(
        ByteArrayDeSerialize(_.toShortSessionKey),
        LongDeSerialize,
        ByteArrayDeSerialize(_.toMessage)
      )
    )

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy