1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_BigEndianInts_h
8 #define mozilla_BigEndianInts_h
10 #include "mozilla/EndianUtils.h"
16 struct BigEndianUint16
{
18 BigEndianUint16
& operator=(const uint16_t aValue
) {
19 value
= NativeEndian::swapToBigEndian(aValue
);
23 MOZ_IMPLICIT
BigEndianUint16(const uint16_t aValue
) {
24 value
= NativeEndian::swapToBigEndian(aValue
);
28 operator uint16_t() const { return NativeEndian::swapFromBigEndian(value
); }
30 friend inline bool operator==(const BigEndianUint16
& lhs
,
31 const BigEndianUint16
& rhs
) {
32 return lhs
.value
== rhs
.value
;
35 friend inline bool operator!=(const BigEndianUint16
& lhs
,
36 const BigEndianUint16
& rhs
) {
44 struct BigEndianUint32
{
46 BigEndianUint32
& operator=(const uint32_t aValue
) {
47 value
= NativeEndian::swapToBigEndian(aValue
);
51 MOZ_IMPLICIT
BigEndianUint32(const uint32_t aValue
) {
52 value
= NativeEndian::swapToBigEndian(aValue
);
56 operator uint32_t() const { return NativeEndian::swapFromBigEndian(value
); }
64 } // namespace mozilla
66 #endif // mozilla_BigEndianInts_h