Reputation: 725
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!
Upvotes: 0
Views: 1106
Reputation: 132
def getClientError(binaryData: Array[Byte]) : ClientError = {
val tdser = new TDeserializer();
val cliErr = new ClientError()
tdser.deserialize(cliErr, binaryData)
return cliErr
}
Upvotes: -1
Reputation: 105
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)
}
Upvotes: 1