0

I am trying to desrialize a binary message in Scala:

val deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    try {
      val obj = deserializer.deserialize(new ClientError{}, input._2.toArray)

Where ClientError is the trait generated with Scrooge from a Thrift file. The problem is, that deserialize() expects a TBase object, but TBase is an interface. How do I do this? Do I have to create a new class which implements both? Thx for any help!

olkoza
  • 715
  • 2
  • 17
  • 35

2 Answers2

1

Try this:

def decode(bytes: Array[Byte]): ClientError = {
  val protocolFactory = new TBinaryProtocol.Factory
  val buffer = new TMemoryInputTransport(bytes)
  val proto = protocolFactory.getProtocol(buffer)
  ClientError.decode(proto)
}
Stephen Corgiat
  • 105
  • 1
  • 7
  • Thank you! I couldn't test that yet, I am having trouble generating test data b/c I can't serialize either (same reason). Can you briefly explain to me the difference between the 2 approaches and the context between Serializer, TBase and the classes/traits generated with scrooge? – olkoza May 20 '16 at 12:31
-1
def getClientError(binaryData: Array[Byte]) : ClientError = {
         val tdser = new TDeserializer();  
         val cliErr = new ClientError()
         tdser.deserialize(cliErr, binaryData)
         return cliErr 
}
Tarun Gupta
  • 132
  • 1
  • 7