Chromium Code Reviews| Index: base/sys_byteorder.h |
| diff --git a/base/sys_byteorder.h b/base/sys_byteorder.h |
| index 500999d6423e7fd4a1d369301f550c954359841a..97e33acfdab33d5093cf5441284eb5f25a314c2b 100644 |
| --- a/base/sys_byteorder.h |
| +++ b/base/sys_byteorder.h |
| @@ -69,6 +69,30 @@ inline uint64 ByteSwap(uint64 x) { |
| #endif |
| } |
| +// Converts the bytes in |x| from host order (endianness) to little endian, and |
| +// returns the result. |
| +inline uint16 ByteSwapToLE16(uint16 x) { |
| +#if defined(ARCH_CPU_LITTLE_ENDIAN) |
| + return x; |
| +#else |
| + return ByteSwap(x); |
| +#endif |
| +} |
| +inline uint32 ByteSwapToLE32(uint32 x) { |
| +#if defined(ARCH_CPU_LITTLE_ENDIAN) |
| + return x; |
| +#else |
| + return ByteSwap(x); |
| +#endif |
| +} |
| +inline uint64 ByteSwapToLE64(uint64 x) { |
| +#if defined(ARCH_CPU_LITTLE_ENDIAN) |
| + return x; |
| +#else |
| + return ByteSwap(x); |
| +#endif |
|
Ilya Sherman
2012/04/13 20:19:20
Hmm, why are you adding these functions rather tha
jwd
2012/04/13 20:33:44
We decided that we wanted the values in little-end
Ilya Sherman
2012/04/13 21:27:33
Ok, fair enough. Thanks :)
|
| +} |
| + |
| // Converts the bytes in |x| from network to host order (endianness), and |
| // returns the result. |
| inline uint16 NetToHost16(uint16 x) { |