thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nobuaki Sukegawa <nsu...@gmail.com>
Subject Re: Using ThriftStructCodec from Scrooge with Thrift
Date Wed, 06 May 2015 02:19:16 GMT
Hi Thomas,

Serialized Thrift struct is not self describing, and determining which
struct to read is kind of done by RPC layer.
Since you're not using Thrift RPC layer, you need to do it in some other
way.

In your case, I would define a single "umbrella" Thrift union containing
all possible struct types as union fields.
This way, you always read the union, eliminating the need to determine
which one to use.
It should look like this:

UmbrellaThrift.decode(protocol) match {
  case UmbrellaThrift.CostThrift(cost) =>
    // ...

On Wed, May 6, 2015 at 2:57 AM, Thomas Pocreau <thomas@colisweb.com> wrote:

> Hi,
>
> I'm new to thrift.
> I'm trying to use Thrift (without rpc) and Scrooge with Scala, Akka and
> Kafka.
>
> I feels like I'm not using the full framework but I can't find the entry
> point.
>
> For now I'm using encoder and decode methods right from ThriftStructCodec3
> Encoding :
>
> val cost = Cost("defaultCost", 1)
> val protocol = new TCompactProtocol.Factory
> val transport = new TMemoryBuffer(100)
> CostThrift.encoder(cost, protocol.getProtocol(transport))
> producer.send(new KeyedMessage(topic, transport.getArray, transport.getArray))
>
> decoding :
>
> val protocolFactory = new TCompactProtocol.Factory
>
> case message: Array[Byte] => {
>   val transport = new TIOStreamTransport(new ByteArrayInputStream(message))
>   val protocol = protocolFactory.getProtocol(transport)
>   val cost: CostThrift = CostThrift.decode(protocol)
>
> The first limitation is that I have multiple ThriftStruct and I don't now
> which ThriftStructCodec3 I should use to decode the message.
> I could really use some guidance On how to fit the code generated by
> scrooge inside the thrift framework.
>
> Thanks a lot.
>
> --
> *Thomas Pocreau*
> Recherche & Développement | *Colisweb*
>
> thomas@colisweb.com
> 06 45 12 61 58
> Euratechnologies | 165, Avenue de Bretagne
> 59000 - Lille
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message