Core Endian Reference
| Framework | CoreServices/CoreServices.h |
| Declared in | Endian.h |
Overview
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 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 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:
Universal Binary Programming Guidelines, Second Edition
QuickTime API Reference
Functions by Task
Working With Flippers
-
CoreEndianFlipDataDeprecated in OS X v10.8 -
CoreEndianGetFlipperDeprecated in OS X v10.8 -
CoreEndianInstallFlipperDeprecated in OS X v10.8
Changing the Endian Format
-
Endian16_SwapDeprecated in OS X v10.8 -
Endian32_SwapDeprecated in OS X v10.8 -
Endian64_SwapDeprecated in OS X v10.8
Converting from Big-Endian to Native Format
-
EndianS16_BtoNDeprecated in OS X v10.8 -
EndianS32_BtoNDeprecated in OS X v10.8 -
EndianS64_BtoNDeprecated in OS X v10.8 -
EndianU16_BtoNDeprecated in OS X v10.8 -
EndianU32_BtoNDeprecated in OS X v10.8 -
EndianU64_BtoNDeprecated in OS X v10.8
Converting from Native Format to Big-Endian Format
-
EndianS16_NtoBDeprecated in OS X v10.8 -
EndianS32_NtoBDeprecated in OS X v10.8 -
EndianS64_NtoBDeprecated in OS X v10.8 -
EndianU16_NtoBDeprecated in OS X v10.8 -
EndianU32_NtoBDeprecated in OS X v10.8 -
EndianU64_NtoBDeprecated in OS X v10.8
Converting from Little-Endian Format to Native Format
-
EndianS16_LtoNDeprecated in OS X v10.8 -
EndianS32_LtoNDeprecated in OS X v10.8 -
EndianS64_LtoNDeprecated in OS X v10.8 -
EndianU16_LtoNDeprecated in OS X v10.8 -
EndianU32_LtoNDeprecated in OS X v10.8 -
EndianU64_LtoNDeprecated in OS X v10.8
Converting from Native Format to Little-Endian Format
-
EndianS16_NtoLDeprecated in OS X v10.8 -
EndianS32_NtoLDeprecated in OS X v10.8 -
EndianS64_NtoLDeprecated in OS X v10.8 -
EndianU16_NtoLDeprecated in OS X v10.8 -
EndianU32_NtoLDeprecated in OS X v10.8 -
EndianU64_NtoLDeprecated in OS X v10.8
Converting from Big-Endian to Little-Endian Format
-
EndianS16_BtoLDeprecated in OS X v10.8 -
EndianS32_BtoLDeprecated in OS X v10.8 -
EndianS64_BtoLDeprecated in OS X v10.8 -
EndianU16_BtoLDeprecated in OS X v10.8 -
EndianU32_BtoLDeprecated in OS X v10.8 -
EndianU64_BtoLDeprecated in OS X v10.8
Converting From Little-Endian to Big-Endian Format
-
EndianS16_LtoBDeprecated in OS X v10.8 -
EndianS32_LtoBDeprecated in OS X v10.8 -
EndianS64_LtoBDeprecated in OS X v10.8 -
EndianU16_LtoBDeprecated in OS X v10.8 -
EndianU32_LtoBDeprecated in OS X v10.8 -
EndianU64_LtoBDeprecated in OS X v10.8
Callbacks
CoreEndianFlipProc
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 );
Parameters
- dataDomain
An
OSTypevalue that specifies the domain to which the flipper callback applies. The valuekCoreEndianResourceManagerDomainsignifies the domain is resource data. The valuekCoreEndianAppleEventManagerDomainsignifies the domain is Apple event data. See “Domain Types” for more information on the values that can be passed to your callback.- dataType
The type of data to be byte swapped by the callback. This is the four character code of the resource type or Apple event.
- id
The resource id of the data type. The value
0signifies the data is not a resource.- dataPtr
On input, points to the data to be flipped. On output, points to the byte-swapped data.
- dataSize
The size of the data pointed to the by the
dataPtrparameter.- currentlyNative
A Boolean value that indicates the direction to byte swap. The value
truespecifies the data pointed to by thedataPtrparameter uses the byte ordering of the currently executing code. On a PowerPC system,truespecifies that the data is in big-endian format. On an x86 system,truespecifies that the data is in little-endian format.- refcon
A 32-bit value that contains or refers to data needed by the callback.
Return Value
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.
Discussion
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).
Availability
- Deprecated in OS X v10.8.
Declared In
Endian.hData Types
BigEndianLong
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;
Fields
bigEndianValueA long value.
Availability
- Available in OS X v10.0 and later.
Declared In
Endian.hBigEndianUnsignedLong
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;
Fields
bigEndianValueAn unsigned long value.
Availability
- Available in OS X v10.0 and later.
Declared In
Endian.hBigEndianShort
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;
Fields
bigEndianValueA short value.
Availability
- Available in OS X v10.0 and later.
Declared In
Endian.hBigEndianUnsignedShort
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;
Fields
bigEndianValueAn unsigned short value.
Availability
- Available in OS X v10.0 and later.
Declared In
Endian.hBigEndianFixed
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;
Fields
bigEndianValueA fixed value.
Availability
- Available in OS X v10.0 and later.
Declared In
Endian.hBigEndianUnsignedFixed
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;
Fields
bigEndianValueAn unsigned fixed value.
Availability
- Available in OS X v10.0 and later.
Declared In
Endian.hBigEndianOSType
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;
Fields
bigEndianValueAn OSType value.
Availability
- Available in OS X v10.0 and later.
Constants
Domain Types
Specify the domain to which a flipper callback should be applied.
enum {
kCoreEndianResourceManagerDomain = 'rsrc',
kCoreEndianAppleEventManagerDomain = 'aevt'
};
Constants
kCoreEndianResourceManagerDomainSpecifies that the domain is limited to the resources for a specific application.
Available in OS X v10.4 and later.
Declared in
Endian.h.kCoreEndianAppleEventManagerDomainSpecifies that the domain is limited to Apple events.
Available in OS X v10.4 and later.
Declared in
Endian.h.
Discussion
The data types have specific meanings within their domain, although some data types can be registered with the same callback in several domains.
Availability
- Available in OS X v10.3 and later.
© 2005, 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-07-23)