diff options
Diffstat (limited to 'src/google/protobuf/stubs/common.cc')
-rw-r--r-- | src/google/protobuf/stubs/common.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index 7b15be44..16d78528 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -320,6 +320,24 @@ void Mutex::AssertHeld() { #endif // =================================================================== +// emulates google3/util/endian/endian.h +// +// TODO(xiaofeng): PROTOBUF_LITTLE_ENDIAN is unfortunately defined in +// google/protobuf/io/coded_stream.h and therefore can not be used here. +// Maybe move that macro definition here in the furture. +uint32 ghtonl(uint32 x) { + union { + uint32 result; + uint8 result_array[4]; + }; + result_array[0] = static_cast<uint8>(x >> 24); + result_array[1] = static_cast<uint8>((x >> 16) & 0xFF); + result_array[2] = static_cast<uint8>((x >> 8) & 0xFF); + result_array[3] = static_cast<uint8>(x & 0xFF); + return result; +} + +// =================================================================== // Shutdown support. namespace internal { |