thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Slee <ms...@fb.com>
Subject Re: how can I pass fixed byte order parameters in thrift?
Date Tue, 05 Jun 2012 02:01:58 GMT
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" <szj087@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.
>


Mime
View raw message