thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Pocreau <tho...@colisweb.com>
Subject Re: Using ThriftStructCodec from Scrooge with Thrift
Date Wed, 06 May 2015 12:59:31 GMT
Thanks a lot for your help,
It worked like a charm.

Encoding :

val cost = Pheromones.CostThrift(Cost("defaultCost", 1))
val protocol = new TCompactProtocol.Factory
val transport = new TMemoryBuffer(100)
Pheromones.encode(cost, protocol.getProtocol(transport))
producer.send(new KeyedMessage(topic, transport.getArray, transport.getArray))


Decoding :

val input = new ByteArrayInputStream(message)
val transport = new TIOStreamTransport(input)
val protocol = protocolFactory.getProtocol(transport)
val thriftStruct = Pheromones.decode(protocol) match {
  case Pheromones.CostThrift(cost) => cost



2015-05-06 4:19 GMT+02:00 Nobuaki Sukegawa <nsukeg@gmail.com>:

> 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
> >
> >
> >
>



-- 
*Thomas Pocreau*
Recherche & Développement | *Colisweb*

thomas@colisweb.com
06 45 12 61 58
Euratechnologies | 165, Avenue de Bretagne
59000 - Lille

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