Topic: Byte Swapping


Author: cooky451@gmail.com
Date: Thu, 28 Mar 2013 06:24:44 -0700 (PDT)
Raw View
------=_Part_6042_8610394.1364477084491
Content-Type: text/plain; charset=ISO-8859-1

The proposed byte swapping functions (n3620) are not sufficient for some
needs, in particular there is no way to convert from host order to little
endian. I would like to propose additional functions:

template <typename T>
T host_to_be(T value);

template <typename T>
T host_to_le(T value);

template <typename T>
T be_to_host(T value);

template <typename T>
T le_to_host(T value);

These functions are useful when dealing with little endian protocols / data
formats and serialization in general.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



------=_Part_6042_8610394.1364477084491
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

The proposed byte swapping functions (n3620) are not sufficient for some ne=
eds, in particular there is no way to convert from host order to little end=
ian. I would like to propose additional functions:<div><br></div><div>templ=
ate &lt;typename T&gt;</div><div>T host_to_be(T value);</div><div><br></div=
><div>template &lt;typename T&gt;</div><div>T host_to_le(T value);</div><di=
v><br></div><div><div>template &lt;typename T&gt;</div><div>T be_to_host(T =
value);</div></div><div><br></div><div><div>template &lt;typename T&gt;</di=
v><div>T le_to_host(T value);</div></div><div><br></div><div>These function=
s are useful when dealing with little endian protocols / data formats and s=
erialization in general.</div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_6042_8610394.1364477084491--

.


Author: cooky451@gmail.com
Date: Thu, 28 Mar 2013 06:27:43 -0700 (PDT)
Raw View
------=_Part_23_9213125.1364477263370
Content-Type: text/plain; charset=ISO-8859-1

All functions should be constexpr of course, as proposed for ntoh and hton
in n3620.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



------=_Part_23_9213125.1364477263370
Content-Type: text/html; charset=ISO-8859-1

All functions should be constexpr of course, as proposed for ntoh and hton in&nbsp;n3620.

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en">http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_23_9213125.1364477263370--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 28 Mar 2013 15:35:56 +0200
Raw View
On 28 March 2013 15:27,  <cooky451@gmail.com> wrote:
> All functions should be constexpr of course, as proposed for ntoh and hton
> in n3620.

This issue has already been raised in the Networking Study Group
internally, so we are likely
to have a discussion about it. Also, fyi, some existing practice is in
http://qt-project.org/doc/qt-4.8/qtendian.html

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



.


Author: Aleksandar Fabijanic <aleks.fabijanic@gmail.com>
Date: Thu, 28 Mar 2013 09:14:00 -0500
Raw View
On Thu, Mar 28, 2013 at 8:35 AM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:

> to have a discussion about it. Also, fyi, some existing practice is in
> http://qt-project.org/doc/qt-4.8/qtendian.html

Here's our $.02:

http://pocoproject.org/docs/Poco.ByteOrder.html

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



.


Author: Olaf van der Spek <olafvdspek@gmail.com>
Date: Sun, 31 Mar 2013 07:31:25 -0700 (PDT)
Raw View
------=_Part_2701_5789685.1364740285310
Content-Type: text/plain; charset=ISO-8859-1

Op donderdag 28 maart 2013 14:35:56 UTC+1 schreef Ville Voutilainen het
volgende:

> On 28 March 2013 15:27,  <cook...@gmail.com <javascript:>> wrote:
> > All functions should be constexpr of course, as proposed for ntoh and
> hton
> > in n3620.
>
> This issue has already been raised in the Networking Study Group
> internally, so we are likely
> to have a discussion about it. Also, fyi, some existing practice is in
> http://qt-project.org/doc/qt-4.8/qtendian.html
>

They appear to be missing to/from native, byte swap functions and unsigned
variants.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



------=_Part_2701_5789685.1364740285310
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Op donderdag 28 maart 2013 14:35:56 UTC+1 schreef Ville Voutilainen het vol=
gende:<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 28 March 2013 15:=
27, &nbsp;&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mail=
to=3D"yBBgjqbcD2AJ">cook...@gmail.com</a>&gt; wrote:
<br>&gt; All functions should be constexpr of course, as proposed for ntoh =
and hton
<br>&gt; in n3620.
<br>
<br>This issue has already been raised in the Networking Study Group
<br>internally, so we are likely
<br>to have a discussion about it. Also, fyi, some existing practice is in
<br><a href=3D"http://qt-project.org/doc/qt-4.8/qtendian.html" target=3D"_b=
lank">http://qt-project.org/doc/qt-<wbr>4.8/qtendian.html</a>
<br></blockquote><div><br></div><div>They appear to be missing to/from nati=
ve, byte swap functions and unsigned variants.</div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_2701_5789685.1364740285310--

.


Author: Markus Mayer <lotharlutz@gmx.de>
Date: Fri, 24 May 2013 16:47:56 +0200
Raw View
On 03/31/2013 04:31 PM, Olaf van der Spek wrote:
> Op donderdag 28 maart 2013 14:35:56 UTC+1 schreef Ville Voutilainen het
> volgende:
>
>     On 28 March 2013 15:27,  <cook...@gmail.com <javascript:>> wrote:
>      > All functions should be constexpr of course, as proposed for ntoh
>     and hton
>      > in n3620.
>
>     This issue has already been raised in the Networking Study Group
>     internally, so we are likely
>     to have a discussion about it. Also, fyi, some existing practice is in
>     http://qt-project.org/doc/qt-4.8/qtendian.html
>     <http://qt-project.org/doc/qt-4.8/qtendian.html>
>
>
> They appear to be missing to/from native, byte swap functions and
> unsigned variants.

I would suggest another approach:

enum byte_order
{
Little,
Big
//Any other byte order you can think of
};

//Some alternative names
const byte_order NATIVE_BYTE_ORDER = byte_order::Little; //Depends on
actual architecture
const byte_order NETWORK_BYTE_ORDER = byte_order::Big; //Just another
alternative name

tempalte<byte_order from, byte_order to, class T>
T convertByteOrder(T value);

Usage:
int toConvert = 5;
int converted = convertByteOrder<NATIVE_BYTE_ORDER,
byte_order::Big>(toConvert);


Benefits:
- There is a way of querying which byte order my target hardware has.
(e.g. if(NATIVE_BYTE_ORDER == byte_order::Big))
- Additional byte orders can be added easily

Drawbacks:
- from and to must be know on compile time (possible solution:
  T convertByteOrder(T value, byte_order from, byte_order to);)
- More to write (possible solution:
  tempalte<byte_order from, byte_order to = NATIVE_BYTE_ORDER, class T>
T convertByteOrder(T value);)



Regards

Markus

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.



.