Framework | CoreServices/CoreServices.h |
Declared in | Endian.h |
Core Endian Reference provides routines for converting data between big endian and little endian format. These routines are useful for developers who write code that must compile for multiple architectures, including:
Macintosh developers who want to produce a universal binary.
QuickTime developers who want their code to run in Windows as well as in Mac OS X.
Both QuickTime and Macintosh developers can use this API to handle reading or writing data to a file or network packet.
Macintosh developers can use this API to create and install callbacks that are invoked by Mac OS X automatically when your application:
reads and writes custom resource data
sends or receives custom Apple events
reads and writes custom pasteboard data
The functions in this API are designed to do nothing when the target runtime is already in the desired format.
For more information see:
QuickTime API Reference
Calls the flipper callback associated with the specified data type.
OSStatus CoreEndianFlipData ( OSType dataDomain, OSType dataType, SInt16 id, void *data, ByteCount dataLen, Boolean currentlyNative );
An OSType
value
that specifies the domain of the flipper callback you want to invoke.
Pass kCoreEndianResourceManagerDomain
if your callback applies to resource data. Pass kCoreEndianAppleEventManagerDomain
if
your callback applies to Apple event data. See “Domain Types” for more information.
An OSType
value
that specifies the type of data that needs to be byte-swapped. This
is the four character code of the resource type or Apple event.
This never needs to be byte-swapped even though GDB and Xcode display
the resource in byte-swapped order.
The resource ID of the data type. The Resource
Manager byte-swaps this for you so you can compare the resource
ID against constants in your code. If the data is not a resource,
pass 0
.
A pointer to the first byte of the data to be byte swapped.
The length of the data (in bytes) to be byte swapped.
A Boolean value that indicates the direction
to byte swap. Pass true
when the
data specified by the data
parameter
uses the byte ordering of the currently executing code. On a PowerPC
system, true
specifies
that the data is in big-endian format. On an x86 system, true
specifies
that the data is in little-endian format.
A result code. Returns noErr
if
the data is byte swapped and handlerNotFound
if
the data is not byte swapped. Note that data is only byte swapped
if it needs to be byte swapped.
Endian.h
Obtains the flipper callback that is installed for the specified data type.
OSStatus CoreEndianGetFlipper ( OSType dataDomain, OSType dataType, CoreEndianFlipProc *proc, void **refcon );
An OSType
value
that specifies the domain of the flipper callback you want to obtain.
Pass kCoreEndianResourceManagerDomain
to obtain a callback that applies to resource data. Pass kCoreEndianAppleEventManagerDomain
to
obtain a callback that applies to Apple event data. See “Domain Types” for
more information.
An OSType
value
that specifies the type of data associated with the flipper callback
you want to obtain. This is the four character code of the resource type
or Apple event. This never needs to be byte-swapped even though GDB
and Xcode display the resource in byte-swapped order.
On output, points to the flipper callback
that is installed for the data type specified by the dataType
parameter.
On output, points to a 32-bit value that references callback-specific data.
A result code. Returns noErr
if
the flipper callback is found.
You can call the function CoreEndianGetFlipper
to
determine whether a flipper for a given data type is available.
Endian.h
Installs a flipper callback for the specified data type.
OSStatus CoreEndianInstallFlipper ( OSType dataDomain, OSType dataType, CoreEndianFlipProc proc, void *refcon );
An OSType
value
that specifies the domain to which the flipper callback applies.
Pass kCoreEndianResourceManagerDomain
if your callback applies to resource data. Pass kCoreEndianAppleEventManagerDomain
if
your callback applies to Apple event data. See “Domain Types” for more information.
An OSType
value
that specifies the type of data for which you want your flipper
callback installed. This is the four character code of the resource
type or Apple event.
A pointer to your flipper callback. The flipper callback is installed into a per-process table that is searched before the system table.
A 32-bit value containing or referring to data needed by the callback.
A result code. Returns noErr
if
your flipper callback is installed.
You should install the callback by calling the function CoreEndianInstallFlipper
when your
application calls its initialization routine or when you open your
resource file.
Endian.h
Changes the endian format of an unsigned 16-bit integer.
UInt16 Endian16_Swap ( UInt16 value );
An unsigned 16-bit integer input.
The unsigned 16-bit integer result.
Endian.h
Changes the endian format of an unsigned 32-bit integer.
UInt32 Endian32_Swap ( UInt32 value );
An unsigned 32-bit integer input.
The unsigned 32-bit integer result.
Endian.h
Changes the endian format of an unsigned 64-bit integer.
static UInt64 Endian64_Swap ( UInt64 value );
An unsigned 64-bit integer input.
The unsigned 64-bit integer result.
Endian.h
Converts a signed 16-bit big-endian value to the equivalent little-endian value.
SInt16 EndianS16_BtoL ( SInt16 value );
A signed 16-bit big-endian value.
The equivalent little-endian value.
Endian.h
Converts a signed 16-bit big-endian value to the equivalent value in the computer’s native format.
SInt16 EndianS16_BtoN ( SInt16 value );
A signed 16-bit big-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts a signed 16-bit little-endian value to the equivalent big-endian value.
SInt16 EndianS16_LtoB ( SInt16 value );
A signed 16-bit little-endian value.
The equivalent big-endian value.
Endian.h
Converts a signed 16-bit little-endian value to the equivalent value in the computer’s native format.
SInt16 EndianS16_LtoN ( SInt16 value );
A signed 16-bit little-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts a signed 16-bit value in the computer’s native format to the equivalent big-endian value.
SInt16 EndianS16_NtoB ( SInt16 value );
A signed 16-bit value in the computer’s native format.
The equivalent big-endian value.
Endian.h
Converts a signed 16-bit value in the computer’s native format to the equivalent little-endian value.
SInt16 EndianS16_NtoL ( SInt16 value );
A signed 16-bit value in the computer’s native format.
The equivalent little-endian value.
Endian.h
Converts a signed 32-bit big-endian value to the equivalent little-endian value.
SInt32 EndianS32_BtoL ( SInt32 value );
A signed 32-bit big-endian value.
The equivalent little-endian value.
Endian.h
Converts a signed 32-bit big-endian value to the equivalent value in the computer’s native format.
SInt32 EndianS32_BtoN ( SInt32 value );
A signed 32-bit big-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts a signed 32-bit little-endian value to the equivalent big-endian value.
SInt32 EndianS32_LtoB ( SInt32 value );
A signed 32-bit little-endian value.
The equivalent big-endian value.
Endian.h
Converts a signed 32-bit little-endian value to the equivalent value in the computer’s native format.
SInt32 EndianS32_LtoN ( SInt32 value );
A signed 32-bit little-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts a signed 32-bit value in the computer’s native format to the equivalent big-endian value.
SInt32 EndianS32_NtoB ( SInt32 value );
A signed 32-bit value in the computer’s native format.
The equivalent big-endian value.
Endian.h
Converts a signed 32-bit value in the computer’s native format to the equivalent little-endian value.
SInt32 EndianS32_NtoL ( SInt32 value );
A signed 32-bit value in the computer’s native format.
The equivalent little-endian value.
Endian.h
Converts a signed 64-bit big-endian value to the equivalent little-endian value.
SInt64 EndianS64_BtoL ( SInt64 value );
A signed 64-bit big-endian value.
The equivalent little-endian value.
Endian.h
Converts a signed 64-bit big-endian value to the equivalent value in the computer’s native format.
SInt64 EndianS64_BtoN ( SInt64 value );
A signed 64-bit big-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts a signed 64-bit little-endian value to the equivalent big-endian value.
SInt64 EndianS64_LtoB ( SInt64 value );
A signed 64-bit little-endian value.
The equivalent big-endian value.
Endian.h
Converts a signed 64-bit little-endian value to the equivalent value in the computer’s native format.
SInt64 EndianS64_LtoN ( SInt64 value );
A signed 64-bit little-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts a signed 64-bit value in the computer’s native format to the equivalent big-endian value.
SInt64 EndianS64_NtoB ( SInt64 value );
A signed 64-bit value in the computer’s native format.
The equivalent big-endian value.
Endian.h
Converts a signed 64-bit value in the computer’s native format to the equivalent little-endian value.
SInt64 EndianS64_NtoL ( SInt64 value );
A signed 64-bit value in the computer’s native format.
The equivalent little-endian value.
Endian.h
Converts an unsigned 16-bit big-endian value to the equivalent little-endian value.
UInt16 EndianU16_BtoL ( UInt16 value );
An unsigned 16-bit big-endian value.
The equivalent little-endian value.
Endian.h
Converts an unsigned 16-bit big-endian value to the equivalent value in the computer’s native format.
UInt16 EndianU16_BtoN ( UInt16 value );
An unsigned 16-bit big-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts an unsigned 16-bit little-endian value to the equivalent big-endian value.
UInt16 EndianU16_LtoB ( UInt16 value );
An unsigned 16-bit little-endian value.
The equivalent big-endian value.
Endian.h
Converts an unsigned 16-bit little-endian value to the equivalent value in the computer’s native format.
UInt16 EndianU16_LtoN ( UInt16 value );
An unsigned 16-bit little-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts an unsigned 16-bit value in the computer’s native format to the equivalent big-endian value.
UInt16 EndianU16_NtoB ( UInt16 value );
An unsigned 16-bit value in the computer’s native format.
The equivalent big-endian value.
Endian.h
Converts an unsigned 16-bit value in the computer’s native format to the equivalent little-endian value.
UInt16 EndianU16_NtoL ( UInt16 value );
An unsigned 16-bit value in the computer’s native format.
The equivalent little-endian value.
Endian.h
Converts an unsigned 32-bit big-endian value to the equivalent little-endian value.
UInt32 EndianU32_BtoL ( UInt32 value );
An unsigned 32-bit big-endian value.
The equivalent little-endian value.
Endian.h
Converts an unsigned 32-bit big-endian value to the equivalent value in the computer’s native format.
UInt32 EndianU32_BtoN ( UInt32 value );
An unsigned 32-bit big-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts an unsigned 32-bit little-endian value to the equivalent big-endian value.
UInt32 EndianU32_LtoB ( UInt32 value );
An unsigned 32-bit little-endian value.
The equivalent big-endian value.
Endian.h
Converts an unsigned 32-bit little-endian value to the equivalent value in the computer’s native format.
UInt32 EndianU32_LtoN ( UInt32 value );
An unsigned 32-bit little-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts an unsigned 32-bit value in the computer’s native format to the equivalent big-endian value.
UInt32 EndianU32_NtoB ( UInt32 value );
An unsigned 32-bit value in the computer’s native format.
The equivalent big-endian value.
Endian.h
Converts an unsigned 32-bit value in the computer’s native format to the equivalent little-endian value.
UInt32 EndianU32_NtoL ( UInt32 value );
An unsigned 32-bit value in the computer’s native format.
The equivalent little-endian value.
Endian.h
Converts an unsigned 64-bit big-endian value to the equivalent little-endian value.
UInt64 EndianU64_BtoL ( UInt64 value );
An unsigned 64-bit big-endian value.
The equivalent little-endian value.
Endian.h
Converts an unsigned 64-bit big-endian value to the equivalent value in the computer’s native format.
UInt64 EndianU64_BtoN ( UInt64 value );
An unsigned 64-bit big-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts an unsigned 64-bit little-endian value to the equivalent big-endian value.
UInt64 EndianU64_LtoB ( UInt64 value );
An unsigned 64-bit little-endian value.
The equivalent big-endian value.
Endian.h
Converts an unsigned 64-bit little-endian value to the equivalent value in the computer’s native format.
UInt64 EndianU64_LtoN ( UInt64 value );
An unsigned 64-bit little-endian value.
The equivalent value in the computer’s native format.
Endian.h
Converts an unsigned 64-bit value in the computer’s native format to the equivalent big-endian value.
UInt64 EndianU64_NtoB ( UInt64 value );
An unsigned 64-bit value in the computer’s native format.
The equivalent big-endian value.
Endian.h
Converts an unsigned 64-bit value in the computer’s native format to the equivalent little-endian value.
UInt64 EndianU64_NtoL ( UInt64 value );
An unsigned 64-bit value in the computer’s native format.
The equivalent little-endian value.
Endian.h
Defines a pointer to a callback function that byte-swaps your custom data.
typedef CALLBACK_API (OSStatus, CoreEndianFlipProc) (OSType dataDomain, OSType dataType, short id, void *dataPtr, UInt32 dataSize, Boolean currentlyNative, void *refcon );
You would declare your flipper callback function as follows
if your were to name it MyCoreEndianFlipProc
:
OSStatus MyCoreEndianFlipProc ( OSType dataDomain, OSType dataType, short id, void *dataPtr, UInt32 dataSize, Boolean currentlyNative, void *refcon );
An OSType
value
that specifies the domain to which the flipper callback applies.
The value kCoreEndianResourceManagerDomain
signifies the domain is resource data. The value kCoreEndianAppleEventManagerDomain
signifies
the domain is Apple event data. See “Domain Types” for more information
on the values that can be passed to your callback.
The type of data to be byte swapped by the callback. This is the four character code of the resource type or Apple event.
The resource id of the data type. The value 0
signifies
the data is not a resource.
On input, points to the data to be flipped. On output, points to the byte-swapped data.
The size of the data pointed to the by the dataPtr
parameter.
A Boolean value that indicates the direction
to byte swap. The value true
specifies
the data pointed to by the dataPtr
parameter
uses the byte ordering of the currently executing code. On a PowerPC
system, true
specifies
that the data is in big-endian format. On an x86 system, true
specifies
that the data is in little-endian format.
A 32-bit value that contains or refers to data needed by the callback.
A result code that
indicates whether the byte swapping is successful. Your callback
should return noErr
if
the resource is byte swapped without error, handlerNotFound
if
you chose not to byte swap the data, and the appropriate result
code to indicate an error condition if the data is bad. The result
code you return is propagated through the appropriate manager (Resource
Manager (ResError
) or
Apple Event Manager) to the caller.
You should write each flipper callback so it traverses the data structure that contains the data and performs the following tasks:
Byte swaps all Resource Manager counts and lengths so that array indexes are associated with the appropriate value
Byte swaps all integers and longs so that when you read them into variables of a compatible type the values can be operated on correctly (such as numerical, offset, and shift operations)
A flipper callback must be bidirectional because it can be called by the Resource Manager or Apple Event Manager when you read data as well as when you write data. The system ensures that your flipper callback is invoked at the appropriate times.
Your flipper callback is not invoked on a microprocessor that
uses big-endian byte ordering. It is called with currentlyNative
set
to false
when data is
read (or received) and true
when
the data is set to be written (or sent).
Endian.h
Protects a big-endian long value from being changed by little-endian code.
// Little-endian host struct BigEndianLong { long bigEndianValue; }; typedef struct BigEndianLong BigEndianLong; // Big-endian host typedef long BigEndianLong;
bigEndianValue
A long value.
Endian.h
Protects a big-endian unsigned long value from being changed by little-endian code.
// Little-endian host struct BigEndianUnsignedLong { unsigned long bigEndianValue; }; typedef struct BigEndianUnsignedLong BigEndianUnsignedLong; // Big-endian host typedef unsigned long BigEndianUnsignedLong;
bigEndianValue
An unsigned long value.
Endian.h
Protects a big-endian short value from being changed by little-endian code.
// Little-endian host struct BigEndianShort { short bigEndianValue; }; typedef struct BigEndianShort BigEndianShort; // Big-endian host typedef short BigEndianShort;
bigEndianValue
A short value.
Endian.h
Protects a big-endian unsigned short value from being changed by little-endian code.
// Little-endian host struct BigEndianUnsignedShort { unsigned short bigEndianValue; }; typedef struct BigEndianUnsignedShort BigEndianUnsignedShort; // Big-endian host typedef unsigned short BigEndianUnsignedShort;
bigEndianValue
An unsigned short value.
Endian.h
Protects a big-endian Fixed value from being changed by little-endian code.
// Little-endian host struct BigEndianFixed { Fixed bigEndianValue; }; typedef struct BigEndianFixed BigEndianFixed; // Big-endian host typedef Fixed BigEndianFixed;
bigEndianValue
A fixed value.
Endian.h
Protects a big-endian unsigned Fixed value from being changed by little-endian code.
// Little-endian host struct BigEndianUnsignedFixed { UnsignedFixed bigEndianValue; }; typedef struct BigEndianUnsignedFixed BigEndianUnsignedFixed; // Big-endian host typedef UnsignedFixed BigEndianUnsignedFixed;
bigEndianValue
An unsigned fixed value.
Endian.h
Protects a big-endian OSType value from being changed by little-endian code.
// Little-endian host struct BigEndianOSType { OSType bigEndianValue; }; typedef struct BigEndianOStype BigEndianOStype; // Big-endian host typedef OSType BigEndianOSType;
bigEndianValue
An OSType value.
Specify the domain to which a flipper callback should be applied.
enum { kCoreEndianResourceManagerDomain = 'rsrc', kCoreEndianAppleEventManagerDomain = 'aevt' };
kCoreEndianResourceManagerDomain
Specifies that the domain is limited to the resources for a specific application.
Available in Mac OS X v10.4 and later.
Declared in Endian.h
.
kCoreEndianAppleEventManagerDomain
Specifies that the domain is limited to Apple events.
Available in Mac OS X v10.4 and later.
Declared in Endian.h
.
The data types have specific meanings within their domain, although some data types can be registered with the same callback in several domains.
© 2005, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-05-29)