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)


  1. namespace TEST
  2. {

  3. enum endian
  4. {
  5. little = 0,
  6. big = 1,
  7. network = big,
  8. #ifdef INTEL_CPU
  9. host = little,
  10. #elif XXX_BIG_ENDIAN_CPU
  11. host = big,
  12. #elif YYY_LITTLE_ENDIAN_CPU
  13. host = big,
  14. #else
  15. #error unknown CPU
  16. #endif
  17. };

  18. typedef endian EndianFrom;
  19. typedef endian EndianTo;

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


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?