Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Why does sf::Packet convert to big endian?  (Read 6107 times)

0 Members and 1 Guest are viewing this topic.

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Why does sf::Packet convert to big endian?
« on: March 02, 2016, 07:47:56 pm »
Windows and OS X are little endian. Linux can theoretically be big endian, but today pretty much 100% use little endian.
Converting to big endian seems like waste of cpu. Is there something I'm missing?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Why does sf::Packet convert to big endian?
« Reply #1 on: March 02, 2016, 09:15:21 pm »
Network byteorder is big endian.

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: Why does sf::Packet convert to big endian?
« Reply #2 on: March 02, 2016, 09:32:38 pm »
Network byteorder is big endian. But as far as I know, as long as both sending and receiving sides use same endian for data, it doesn't matter. Since SFML's platform uses little endian, why is sf::Packet needlessly converting to big endian?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Why does sf::Packet convert to big endian?
« Reply #3 on: March 02, 2016, 09:45:40 pm »
You don't know 100% what's at the other end of the pipe (big/little endian), but everyone agrees that data on the wire is big endian - so everyone can interoperate.
I have a DEC Alpha running Debian Linux that may be very cross if you start assuming that it is little endian and should expect that on the network. Also, little endian machines *know* that everything coming in is big endian and will convert - if it is suddenly little coming in, that conversion will be wrong, at the very least you have backwards compatibility issues with previous sfml versions.
Better to just let the network stay BE as it always has and get fewer headaches. The performance hit is negligible anyway.

(And how on earth did that fscked-up LE byteorder get the upper hand anyway? That's just wrong - BE is the natural thing and the way to go - but I give up...)
« Last Edit: March 02, 2016, 10:50:23 pm by Jesper Juhl »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Why does sf::Packet convert to big endian?
« Reply #4 on: March 02, 2016, 10:35:27 pm »
And because we use a "standard" byte order, functions that convert from/to it are widely available on all target platforms, there's no need to reinvent the wheel.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Why does sf::Packet convert to big endian?
« Reply #5 on: March 02, 2016, 11:56:36 pm »
But as far as I know, as long as both sending and receiving sides use same endian for data, it doesn't matter.
Yes, just that the "as long" is not helpful if the code breaks occasionally. In reality you don't know the other's host endianess.

Since SFML's platform uses little endian, why is sf::Packet needlessly converting to big endian?
SFML's network sockets cannot just communicate to other SFML endpoints. They run TCP and UDP protocols which are ubiquituous, you can talk to anything that implements them. For example, I've once written a sf::UdpSocket that sends to a Java DatagramSocket.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: Why does sf::Packet convert to big endian?
« Reply #6 on: March 03, 2016, 01:19:01 am »
But as far as I know, as long as both sending and receiving sides use same endian for data, it doesn't matter.
Yes, just that the "as long" is not helpful if the code breaks occasionally. In reality you don't know the other's host endianess.
I don't really understand what you are saying. I'm talking specifically about sf::Packet. Users who use that class don't have to know anything about endianess. So why would the code suddenly break? Also, I just said that the platforms on which SFML runs on use little endian.

Since SFML's platform uses little endian, why is sf::Packet needlessly converting to big endian?
SFML's network sockets cannot just communicate to other SFML endpoints. They run TCP and UDP protocols which are ubiquituous, you can talk to anything that implements them. For example, I've once written a sf::UdpSocket that sends to a Java DatagramSocket.
SFML's UdpSocket and TcpSocket can talk to other UDP and TCP sockets, but sf::Packet is supposed to be used only within SFML.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Why does sf::Packet convert to big endian?
« Reply #7 on: March 03, 2016, 12:43:19 pm »
Yes, such packets were designed to be used in SFML <-> SFML applications communication. But since we don't have the strong guarantee that all platforms on which SFML runs are using the same endianness, why add such limitations? Did you experience a significant bottleneck due to this bytes reordering?
SFML / OS X developer

scellow

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Why does sf::Packet convert to big endian?
« Reply #8 on: May 20, 2016, 02:18:02 am »
C# use little endian, i'm not using sfml network but i think the best would be an option to choose what endian to use

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Why does sf::Packet convert to big endian?
« Reply #9 on: May 20, 2016, 07:53:29 am »
Quote
C# use little endian
What does that mean? Network byte order is independant from any language, it is just a convention. And by the way, C# has functions to work with network byte order too.

Quote
i think the best would be an option to choose what endian to use
Since this is an internal format anyway (ie. you don't decode it yourself), what would that change?
Laurent Gomila - SFML developer