thrift serialization and deserialization

901 views
Skip to first unread message

anand

unread,
Jun 9, 2012, 6:12:00 AM6/9/12
to java-serialization-benchmarking
I am trying to understand thrift.

I want to convert a hash to thrift object, is that possible? ( just
like how you convert a hash to json or yaml )

If yes, can you show me how this example hash will look like in thrift
format?

a = {:first_key=>
[{:x=>"some_x",
:y=>"some_y"
}], :second_key=> "some other value"}

are there any standard methods that will do this for me in ruby? (just
like .to_json and .to_yaml)

Tatu Saloranta

unread,
Jun 9, 2012, 9:47:06 PM6/9/12
to java-serializat...@googlegroups.com
Thrift requires a schema to specify structure of objects to
serialize/deserialize.
And while there are multiple possible output formats, in practice
one(s) used in production are binary formats. So examples are not very
meaningful: property names become property ids and so on.

So, exact bytes constructed for the example depend on Thrift Schema
used (and one must be used); and these will not be piece of text but a
binary sequence.

For this reason there aren't too many conversion tools, although one
can theoretically convert arbitrary hash maps to Thrift schema defined
structures.

-+ Tatu +-

Anand Hegde

unread,
Jun 9, 2012, 11:54:45 PM6/9/12
to java-serializat...@googlegroups.com
If I want to convert a file into thrfit format, I will give this in my .thrift definition file

struct my_file {

1: string file_name
2: string file_contents

}

After this how do I convert a file into the thrift format in ruby?

Is there a method that will do this for me?

Tatu Saloranta

unread,
Jun 10, 2012, 8:28:03 PM6/10/12
to java-serializat...@googlegroups.com
I think you should follow this up on a Thrift mailing list. For other
languages code generation is used, for example with Java to generate
Java source codes to handle serialization, deserialization, and you
use those. I assume this may be the way it's done with Ruby, but
perhaps it might be more dynamic.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages