Endians

Programming, for all ages and all languages.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Endians

Post by Love4Boobies »

Implementations are likely have different internal representations. So, if you need to prepare some data for processing on a different implementation, you require a common format. The party preparing and encoding the data is said to serialize it, while the party decoding and processing it is said to deserialize it.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Endians

Post by qw »

All right, I did not know the meaning of "serialization" in this context.

So to properly serialize or deserialize, one must know the internal representation. Or the library should supply some functions that are endian-aware (like ntohl() and relatives).
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Endians

Post by Love4Boobies »

Precisely.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Endians

Post by Brendan »

Hi,
Hobbes wrote:So to properly serialize or deserialize, one must know the internal representation. Or the library should supply some functions that are endian-aware (like ntohl() and relatives).
Things like network packets and files are really arrays of bytes. If you treat them as arrays of bytes then you end up writing code (like "buffer[0] = myInt & 0xFF; buffer[1] = (myInt >> 8 ) & 0xFF;") to do type conversion correctly, and any endian problem disappears by accident.

From this perspective you could say that endian problems are actually "lack of strong type checking" problems.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply