stream_poll stream_set_swap_bytes navigation bar

stream_set_byte_order

Configures the byte order used by the stream for multi-byte data types.

Description

This function determines whether the functions that send and receive t_short's, t_utf16_char's, t_utf32_char's, t_int's, t_long's, or arrays of them, swap the bytes in the individual values.

Byte swapping is only necessary when communicating between processors that use a different endianness. For example, Intel processors are little endian (LSB first) while Motorola processors tend to be big endian (MSB first). By default, no byte swapping takes place. This function compares the byte_order given to the native byte ordering of the platform running the code and tells the stream to swap bytes if the byte orders are different.

For example, if the byte_order is set to STREAM_BYTE_ORDER_LITTLE_ENDIAN and the underlying platform is little endian then no byte swapping takes place. However, if the underlying platform is big endian, then byte swapping is performed on all multi-byte data types sent or received over the stream.

If the byte_order is set to STREAM_BYTE_ORDER_BIG_ENDIAN and the underlying platform is big endian then no byte swapping takes place. However, if the underlying platform is little endian, then byte swapping is performed on all multi-byte data types sent or received over the stream.

If the byte_order is set to STREAM_BYTE_ORDER_NATIVE_ENDIAN then the native byte order of the underlying platform is used and no byte swapping takes place. Native endian is the default byte order.

Note that stream_set_byte_order and stream_set_swap_bytes override each other, so byte swapping is performed according to the last function called.

Prototype

t_error
stream_set_byte_order(t_stream stream, t_stream_byte_order byte_order);
    

Parameters

t_stream stream

A stream established using stream_listen, stream_connect or stream_accept.

t_stream_byte_order byte_order

The desired byte order when sending/receiving multi-byte data types. Valid byte order values are:

Value

Meaning

STREAM_BYTE_ORDER_NATIVE_ENDIAN

Native byte order (no byte swapping performed)

STREAM_BYTE_ORDER_LITTLE_ENDIAN

Little endian byte order (byte swapping performed if platform is big endian)

STREAM_BYTE_ORDER_BIG_ENDIAN

Big endian byte order (byte swapping performed if platform is little endian)

Return value

Returns 0 on success. If an error occurs then a negative error code is returned.

Error codes

This function does not return any error code.

Requirements

Include Files

Libraries

quanser_stream.h

quanser_communications.lib;quanser_runtime.lib;quanser_common.lib

See Also

 

navigation bar