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

sss.openstar.message.payloads.serialize.NewQuorumMemberSerializer.scala Maven / Gradle / Ivy

package sss.openstar.message.payloads.serialize

import sss.ancillary.Serialize._
import sss.openstar.message.payloads.NewQuorumMemberMessage
import sss.openstar.quorumledger._

object NewQuorumMemberSerializer extends Serializer[NewQuorumMemberMessage] {

  override def toBytes(m: NewQuorumMemberMessage): Array[Byte] = {
    ByteArraySerializer(m.tx.toBytes) ++
    SequenceSerializer(m.requiredSigs.toSeq map StringSerializer) ++
      MapSerializer(m.sigs, StringSerializer, ByteArraySerializer)
      .toBytes
  }

  override def fromBytes(b: Array[Byte]): NewQuorumMemberMessage = {
    val extracted = b.extract(
      ByteArrayDeSerialize(_.toAddNode),
      SequenceDeSerialize(_.extract(StringDeSerialize)),
        MapDeSerialize(_.extract(StringDeSerialize), _.extract(ByteArrayDeSerialize))
    )

    NewQuorumMemberMessage(extracted._1, extracted._2.toSet, extracted._3)

  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy