N3783: Network Byte Order Conversion -- Robert Pratte

Note: This paper was adopted on Saturday at the Chicago meeting for the new Networking TS.

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3783

Date: 2013-09-27

Network Byte Order Conversion

by Robert Pratte

Excerpt:

This proposal adds support to C++ for converting between host and network byte order.

Add a Comment

Comments are closed.

Comments (1)

0 0

jjlee said on Oct 9, 2013 09:31 AM:

I think it is not easy to use it.
How to convert FLV UI24 (24 bit unsigned int) by current spec?
How to convert WEBM signed and unsigned interger (1 ~ 8 bytes)?

Could we just have something like below? (Just an idea for thinking, might not be correct)


namespace TEST
{

enum endian
{
little = 0,
big = 1,
network = big,
#ifdef INTEL_CPU
host = little,
#elif XXX_BIG_ENDIAN_CPU
host = big,
#elif YYY_LITTLE_ENDIAN_CPU
host = big,
#else
#error unknown CPU
#endif
};

typedef endian EndianFrom;
typedef endian EndianTo;

template <EndianFrom, EndianTo> class EndianConversion
{
public:
// TFrom and TTo could be any of :
// int8_t, int16_t, int24_t, int32_t, int40_t, int48_t, int56_t, int64_t,
// uint8_t, uint16_t, uint24_t, uint32_t, uint40_t, uint48_t, uint56_t, uint64_t
// and end user could even provide his special type
template <typename TFrom, typename TTo> void convert(const TFrom&, TTo&);
};
};


Above convert() could even throw an exception if conversion is not possible.

There could be some little endian data in FLV (SoundFormat=3, Linear PCM little endian) and WEBM, how can a big endian host to handle it with current spec?