thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xieling <>
Subject Re: Re: how can I pass fixed byte order parameters in thrift?
Date Tue, 05 Jun 2012 02:38:23 GMT
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?

IZP Tech.

From: Mark Slee
Date: 2012-06-05 10:01
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
(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.


On 6/4/12 6:32 PM, "szj087" <> 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
>>     I just wonder, how can I pass fixed byte order parameters in thrift?
>> Thank you very much!
>> XieLing
>> IZP Tech.
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message