From 200b6a88ec013e3e138711a87dc11520d3bd1afd Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Fri, 25 Aug 2000 01:39:17 +0000 Subject: [PATCH] installed --- src/libCom/osi/os/default/osiWireFormat.h | 80 +++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/libCom/osi/os/default/osiWireFormat.h diff --git a/src/libCom/osi/os/default/osiWireFormat.h b/src/libCom/osi/os/default/osiWireFormat.h new file mode 100644 index 000000000..edef0139a --- /dev/null +++ b/src/libCom/osi/os/default/osiWireFormat.h @@ -0,0 +1,80 @@ + +/* + * $Id$ + * + * + * L O S A L A M O S + * Los Alamos National Laboratory + * Los Alamos, New Mexico 87545 + * + * Copyright, 2000, The Regents of the University of California. + * + * + * Author Jeffrey O. Hill + * johill@lanl.gov + */ + +#ifndef osiWireFormat +#define osiWireFormat + +#include "epicsTypes.h" + +// +// The default assumption is that the local floating point format is +// IEEE and that these routines only need to perform byte swapping +// as a side effect of copying an aligned operand into an unaligned +// network byte stream. +// + +// this endian test should vanish during optimization +// and therefore be executed only at compile time +inline bool osiLittleEndian () +{ + static const unsigned endianTest = 1u; + static const char * const pEndianTest = reinterpret_cast < const char * > ( &endianTest ); + if ( *pEndianTest ) { + return true; + } + else { + return false; + } +} + +inline void osiConvertToWireFormat ( const epicsFloat32 &value, unsigned char *pWire ) +{ + const epicsUInt32 * pValue = reinterpret_cast < const epicsUInt32 * > ( &value ); + pWire[0u] = static_cast < unsigned char > ( *pValue >> 24u ); + pWire[1u] = static_cast < unsigned char > ( *pValue >> 16u ); + pWire[2u] = static_cast < unsigned char > ( *pValue >> 8u ); + pWire[3u] = static_cast < unsigned char > ( *pValue >> 0u ); +} + +inline void osiConvertToWireFormat ( const epicsFloat64 &value, unsigned char *pWire ) +{ + const epicsUInt32 *pValue = reinterpret_cast < const epicsUInt32 *> ( &value ); + // this endian test should vanish during optimization + if ( osiLittleEndian () ) { + // little endian + pWire[0u] = static_cast < unsigned char > ( pValue[1] >> 24u ); + pWire[1u] = static_cast < unsigned char > ( pValue[1] >> 16u ); + pWire[2u] = static_cast < unsigned char > ( pValue[1] >> 8u ); + pWire[3u] = static_cast < unsigned char > ( pValue[1] >> 0u ); + pWire[4u] = static_cast < unsigned char > ( pValue[0] >> 24u ); + pWire[5u] = static_cast < unsigned char > ( pValue[0] >> 16u ); + pWire[6u] = static_cast < unsigned char > ( pValue[0] >> 8u ); + pWire[7u] = static_cast < unsigned char > ( pValue[0] >> 0u ); + } + else { + // big endian + pWire[0u] = static_cast < unsigned char > ( pValue[0] >> 24u ); + pWire[1u] = static_cast < unsigned char > ( pValue[0] >> 16u ); + pWire[2u] = static_cast < unsigned char > ( pValue[0] >> 8u ); + pWire[3u] = static_cast < unsigned char > ( pValue[0] >> 0u ); + pWire[4u] = static_cast < unsigned char > ( pValue[1] >> 24u ); + pWire[5u] = static_cast < unsigned char > ( pValue[1] >> 16u ); + pWire[6u] = static_cast < unsigned char > ( pValue[1] >> 8u ); + pWire[7u] = static_cast < unsigned char > ( pValue[1] >> 0u ); + } +} + +#endif // osiWireFormat