You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by xieling <xi...@izptec.com> on 2012/06/05 03:25:38 UTC

how can I pass fixed byte order parameters in thrift?

Hi All,
    I want to transfers IP (IPv4) between client and server, can anyone tell me, which byte-order (host or network) should i used before transfer?
    I just wonder, how can I pass fixed byte order parameters in thrift?

Thank you very much!




XieLing
IZP Tech.

Re: Re: how can I pass fixed byte order parameters in thrift?

Posted by xieling <xi...@izptec.com>.
Hi Mark,
Thank you very much! Your suggestion is perfect!

But I think thrift can make sure the values (host-byte-order) is the same, but not the byte-order.
So, if we want transfer fixed byte order parameters in thrift, can we just use host byte order value, and then, the IP parameter is always in host byte value order?
Is that above right?




XieLing
IZP Tech.
 

From: Mark Slee
Date: 2012-06-05 10:01
To: user@thrift.apache.org; xieling@izptec.com
Subject: Re: how can I pass fixed byte order parameters in thrift?
Thrift automatically does network byte order translations on numeric
fields (i32, i64, u32, u64, etc.). If you transfer your data using these
types, they will end up in host byte order on the target machine. In
C-speak, this means one htonl() call is issued before each transfer and
one corresponding ntohl() call on every numeric type received.

If this is what you're trying to achieve, then yes, it's done for you. No
byte-flipping necessary in your application code.

If you are trying to *avoid* this and ensure a fixed byte-ordering, you're
probably best off doing one of:

(1) use the binary data type, which is just an ordered sequence of raw
bytes
(2) send ip addresses as dot-notated strings, use inet_pton()/inet_ntop()
to encode and parse them
(3) use i32 to represent IP addresses, ALWAYS store in network order - so
have htonl() calls in your application code (high potential for bugs here)

Unless you're seriously bandwidth-sensitive, I'd probably recommend #2 -
converting IPv4 to strings is cheap and easy, hard to screw up or
introduce weird bugs into relative to the other options.

Cheers,
Mark


On 6/4/12 6:32 PM, "szj087" <sz...@gmail.com> wrote:

>Thrift should do that for you if i am right.
>
>
>On 6/5/2012 9:25 AM, xieling wrote:
>> Hi All,
>>     I want to transfers IP (IPv4) between client and server, can anyone
>>tell me, which byte-order (host or network) should i used before
>>transfer?
>>     I just wonder, how can I pass fixed byte order parameters in thrift?
>>
>> Thank you very much!
>>
>>
>>
>>
>> XieLing
>> IZP Tech.
>

Re: how can I pass fixed byte order parameters in thrift?

Posted by Mark Slee <ms...@fb.com>.
Thrift automatically does network byte order translations on numeric
fields (i32, i64, u32, u64, etc.). If you transfer your data using these
types, they will end up in host byte order on the target machine. In
C-speak, this means one htonl() call is issued before each transfer and
one corresponding ntohl() call on every numeric type received.

If this is what you're trying to achieve, then yes, it's done for you. No
byte-flipping necessary in your application code.

If you are trying to *avoid* this and ensure a fixed byte-ordering, you're
probably best off doing one of:

(1) use the binary data type, which is just an ordered sequence of raw
bytes
(2) send ip addresses as dot-notated strings, use inet_pton()/inet_ntop()
to encode and parse them
(3) use i32 to represent IP addresses, ALWAYS store in network order - so
have htonl() calls in your application code (high potential for bugs here)

Unless you're seriously bandwidth-sensitive, I'd probably recommend #2 -
converting IPv4 to strings is cheap and easy, hard to screw up or
introduce weird bugs into relative to the other options.

Cheers,
Mark


On 6/4/12 6:32 PM, "szj087" <sz...@gmail.com> wrote:

>Thrift should do that for you if i am right.
>
>
>On 6/5/2012 9:25 AM, xieling wrote:
>> Hi All,
>>     I want to transfers IP (IPv4) between client and server, can anyone
>>tell me, which byte-order (host or network) should i used before
>>transfer?
>>     I just wonder, how can I pass fixed byte order parameters in thrift?
>>
>> Thank you very much!
>>
>>
>>
>>
>> XieLing
>> IZP Tech.
>


Re: how can I pass fixed byte order parameters in thrift?

Posted by szj087 <sz...@gmail.com>.
Thrift should do that for you if i am right.


On 6/5/2012 9:25 AM, xieling wrote:
> Hi All,
>     I want to transfers IP (IPv4) between client and server, can anyone tell me, which byte-order (host or network) should i used before transfer?
>     I just wonder, how can I pass fixed byte order parameters in thrift?
>
> Thank you very much!
>
>
>
>
> XieLing
> IZP Tech.