You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Alexis Gryta <al...@crisalid.com> on 2014/06/02 19:54:53 UTC

Ruby : How to get thrift type of attribute ?

Hi everybody !

I would like to process many attributes automatically.
But my data are read from a file and they are string type...
I would like to know if there is a solution to know the type of attribute.
Thanks to this, I'll be able to convert string into the right type.

struct Test{
1: i32 id,
2: string name,
3: Enumeration genre
}

test = Test.new
A method which does (for example) :
puts test.id.type  => Give me i32
puts test.string.type  => Give me string
Etc..

I can use test.id.class but it doesn't work .. (tell me nilClass when it
isn't assigned)
And even if "id" is a i32,
test.id = "blabla"  => works... (normally, it shouldn't)
The verification of type is done only when you try to serialize... not when
you assign a value into a thrift object.

Thank you !

Re: Ruby : How to get thrift type of attribute ?

Posted by Nevo Hed <nh...@aereo.com>.
I assumed I was going to find an answer by Jens at SO, but since I didn't I
took a stab at it
http://stackoverflow.com/a/24066653/652904

probably not the most accurate, but what I have at the moment


On Mon, Jun 2, 2014 at 3:43 PM, Jens Geyer <je...@hotmail.com> wrote:

> http://stackoverflow.com/questions/24001945/how-to-get-
> thrift-type-of-an-attribute
>
>
> -----Ursprüngliche Nachricht----- From: Alexis Gryta
> Sent: Monday, June 2, 2014 7:54 PM
> To: user@thrift.apache.org
> Subject: Ruby : How to get thrift type of attribute ?
>
>
> Hi everybody !
>
> I would like to process many attributes automatically.
> But my data are read from a file and they are string type...
> I would like to know if there is a solution to know the type of attribute.
> Thanks to this, I'll be able to convert string into the right type.
>
> struct Test{
> 1: i32 id,
> 2: string name,
> 3: Enumeration genre
> }
>
> test = Test.new
> A method which does (for example) :
> puts test.id.type  => Give me i32
> puts test.string.type  => Give me string
> Etc..
>
> I can use test.id.class but it doesn't work .. (tell me nilClass when it
> isn't assigned)
> And even if "id" is a i32,
> test.id = "blabla"  => works... (normally, it shouldn't)
> The verification of type is done only when you try to serialize... not when
> you assign a value into a thrift object.
>
> Thank you !
>

Re: Ruby : How to get thrift type of attribute ?

Posted by Jens Geyer <je...@hotmail.com>.
http://stackoverflow.com/questions/24001945/how-to-get-thrift-type-of-an-attribute


-----Ursprüngliche Nachricht----- 
From: Alexis Gryta
Sent: Monday, June 2, 2014 7:54 PM
To: user@thrift.apache.org
Subject: Ruby : How to get thrift type of attribute ?

Hi everybody !

I would like to process many attributes automatically.
But my data are read from a file and they are string type...
I would like to know if there is a solution to know the type of attribute.
Thanks to this, I'll be able to convert string into the right type.

struct Test{
1: i32 id,
2: string name,
3: Enumeration genre
}

test = Test.new
A method which does (for example) :
puts test.id.type  => Give me i32
puts test.string.type  => Give me string
Etc..

I can use test.id.class but it doesn't work .. (tell me nilClass when it
isn't assigned)
And even if "id" is a i32,
test.id = "blabla"  => works... (normally, it shouldn't)
The verification of type is done only when you try to serialize... not when
you assign a value into a thrift object.

Thank you !