BDE 4.14.0 Production release
|
Functions | |
bdlb::BigEndianInt16::operator short () const | |
bdlb::BigEndianUint16::operator unsigned short () const | |
bdlb::BigEndianInt32::operator int () const | |
bdlb::BigEndianUint32::operator unsigned int () const | |
bdlb::BigEndianInt64::operator bsls::Types::Int64 () const | |
bdlb::BigEndianUint64::operator bsls::Types::Uint64 () const | |
Provide big-endian integer types.
This component provides generic in-core big-endian integer types bdlb::BigEndianInt16
, bdlb::BigEndianUint16
, bdlb::BigEndianInt32
, bdlb::BigEndianUint32
, bdlb::BigEndianInt64
and bdlb::BigEndianUint64
that store integral values that they represent in a big-endian byte order. For example, an integer value 0x01020304 will be internally stored by the bdlb::BigEndianInt32
object as 0x04030201 on little-endian platforms.
This section illustrates intended use of this component.
This example demonstrates using bdlb::BigEndian
types to represent a structure meant to be exchanged over the network ( which historically uses big-endian byte order ) or stored in-core as big-endian integers. First, we define the structure:
Next, we prepare in-memory representation of the protocol header with protocol version set to 0x1
, message type set to 0x02
and message length set to 0x1234
in the big-endian byte order (most significant bytes first):
Now, we create an instance of the ProtocolHeader
structure and emulate packet reception over the network:
Next, we verify that actual in-core values depend on the endianess of the underlying platform:
Finally, we verify that the received protocol header can be validated on platforms of any endianess:
|
inline |
Return the value stored in this object as a bsls::Types::Int64
in the native byte-order.
|
inline |
Return the value stored in this object as a bsls::Types::Uint64
in the native byte-order.
|
inline |
Return the value stored in this object as a int
in the native byte-order.
|
inline |
Return the value stored in this object as a short
in the native byte-order.
|
inline |
Return the value stored in this object as a unsigned int
in the native byte-order.
|
inline |
Return the value stored in this object as a unsigned short
in the native byte-order.