Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
In Memory Serialization/Deserialization Functions

Functions

posh_u16_tPOSH_WriteU16ToLittle (void *dst, posh_u16_t value)
 
posh_s16_tPOSH_WriteS16ToLittle (void *dst, posh_s16_t value)
 
posh_u32_tPOSH_WriteU32ToLittle (void *dst, posh_u32_t value)
 
posh_s32_tPOSH_WriteS32ToLittle (void *dst, posh_s32_t value)
 
posh_u16_tPOSH_WriteU16ToBig (void *dst, posh_u16_t value)
 
posh_s16_tPOSH_WriteS16ToBig (void *dst, posh_s16_t value)
 
posh_u32_tPOSH_WriteU32ToBig (void *dst, posh_u32_t value)
 
posh_s32_tPOSH_WriteS32ToBig (void *dst, posh_s32_t value)
 
posh_u16_t POSH_ReadU16FromLittle (const void *src)
 
posh_s16_t POSH_ReadS16FromLittle (const void *src)
 
posh_u32_t POSH_ReadU32FromLittle (const void *src)
 
posh_s32_t POSH_ReadS32FromLittle (const void *src)
 
posh_u16_t POSH_ReadU16FromBig (const void *src)
 
posh_s16_t POSH_ReadS16FromBig (const void *src)
 
posh_u32_t POSH_ReadU32FromBig (const void *src)
 
posh_s32_t POSH_ReadS32FromBig (const void *src)
 

Detailed Description

These functions take host endian values and serialize them into
explicit endianess buffers and vice versa.  The 64-bit versions
of these functions can be found under @ref SixtyFourBit

Here's an example usage that serializes a struct into a big-endian buffer:

*
*  struct mystruct
*  {
*  posh_u16_t u16;
*  posh_s32_t s32;
*  };
*
*  void WriteStruct( void *buffer, const struct mystruct *s )
*  {
*  void *p = buffer;
*
*  //The POSH_Write??? functions return a pointer to the next write address
*  p = POSH_WriteU16ToBig( p, &s->u16 );
*  p = POSH_WriteS32ToBig( p, &s->s32 );
*  }
*
*  

Function Documentation

posh_s16_t POSH_ReadS16FromBig ( const void *  src)

Reads a signed 16-bit value from a big-endian buffer

Parameters
src[in]source buffer
Returns
host-endian signed 16-bit value

Definition at line 562 of file posh.cpp.

References POSH_BigS16.

563 {
564  return POSH_BigS16( (*(const posh_s16_t*) src) );
565 }
posh_s16_t POSH_ReadS16FromLittle ( const void *  src)

Reads a signed 16-bit value from a little-endian buffer

Parameters
src[in]source buffer
Returns
host-endian signed 16-bit value

Definition at line 522 of file posh.cpp.

References POSH_LittleS16.

523 {
524  return POSH_LittleS16( (*(const posh_s16_t*) src) );
525 }
posh_s32_t POSH_ReadS32FromBig ( const void *  src)

Reads a signed 32-bit value from a big-endian buffer

Parameters
src[in]source buffer
Returns
host-endian signed 32-bit value

Definition at line 582 of file posh.cpp.

References POSH_BigS32.

Referenced by NetBuffer::getInt32().

583 {
584  return POSH_BigS32( (*(const posh_s32_t*) src) );
585 }
posh_s32_t POSH_ReadS32FromLittle ( const void *  src)

Reads a signed 32-bit value from a little-endian buffer

Parameters
src[in]source buffer
Returns
host-endian signed 32-bit value

Definition at line 542 of file posh.cpp.

References POSH_LittleS32.

543 {
544  return POSH_LittleS32( (*(const posh_s32_t*) src) );
545 }
posh_u16_t POSH_ReadU16FromBig ( const void *  src)

Reads an unsigned 16-bit value from a big-endian buffer

Parameters
src[in]source buffer
Returns
host-endian unsigned 16-bit value

Definition at line 552 of file posh.cpp.

References POSH_BigU16.

Referenced by NetBuffer::getShort(), and s_testSerialization().

553 {
554  return POSH_BigU16( (*(const posh_u16_t*) src) );
555 }
posh_u16_t POSH_ReadU16FromLittle ( const void *  src)

Reads an unsigned 16-bit value from a little-endian buffer

Parameters
src[in]source buffer
Returns
host-endian unsigned 16-bit value

Definition at line 512 of file posh.cpp.

References POSH_LittleU16.

Referenced by s_testSerialization().

513 {
514  return POSH_LittleU16( (*(const posh_u16_t*) src) );
515 }
posh_u32_t POSH_ReadU32FromBig ( const void *  src)

Reads an unsigned 32-bit value from a big-endian buffer

Parameters
src[in]source buffer
Returns
host-endian unsigned 32-bit value

Definition at line 572 of file posh.cpp.

References POSH_BigU32.

Referenced by NetBuffer::getUInt32(), and s_testSerialization().

573 {
574  return POSH_BigU32( (*(const posh_u32_t*) src) );
575 }
posh_u32_t POSH_ReadU32FromLittle ( const void *  src)

Reads an unsigned 32-bit value from a little-endian buffer

Parameters
src[in]source buffer
Returns
host-endian unsigned 32-bit value

Definition at line 532 of file posh.cpp.

References POSH_LittleU32.

Referenced by s_testSerialization().

533 {
534  return POSH_LittleU32( (*(const posh_u32_t*) src) );
535 }
posh_s16_t* POSH_WriteS16ToBig ( void *  dst,
posh_s16_t  value 
)

Writes a signed 16-bit value to a big endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian signed 16-bit value
Returns
a pointer to the location two bytes after dst
Remarks
does no validation of the inputs. This simply calls POSH_WriteU16ToLittle() with appropriate casting.

Definition at line 398 of file posh.cpp.

References POSH_WriteU16ToBig().

399 {
400  return (posh_s16_t*) POSH_WriteU16ToBig( dst, (posh_u16_t) value );
401 }
posh_s16_t* POSH_WriteS16ToLittle ( void *  dst,
posh_s16_t  value 
)

Writes a signed 16-bit value to a little endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian signed 16-bit value
Returns
a pointer to the location two bytes after dst
Remarks
does no validation of the inputs. This simply calls POSH_WriteU16ToLittle() with appropriate casting.

Definition at line 336 of file posh.cpp.

References POSH_WriteU16ToLittle().

337 {
338  return (posh_s16_t*) POSH_WriteU16ToLittle( dst, (posh_u16_t) value );
339 }
posh_s32_t* POSH_WriteS32ToBig ( void *  dst,
posh_s32_t  value 
)

Writes a signed 32-bit value to a big endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian signed 32-bit value
Returns
a pointer to the location four bytes after dst
Remarks
does no validation of the inputs. This simply calls POSH_WriteU32ToBig() with appropriate casting.

Definition at line 429 of file posh.cpp.

References POSH_WriteU32ToBig().

Referenced by NetBuffer::addInt32().

430 {
431  return (posh_s32_t*) POSH_WriteU32ToBig( dst, (posh_u32_t) value );
432 }
posh_s32_t* POSH_WriteS32ToLittle ( void *  dst,
posh_s32_t  value 
)

Writes a signed 32-bit value to a little endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian signed 32-bit value
Returns
a pointer to the location four bytes after dst
Remarks
does no validation of the inputs. This simply calls POSH_WriteU32ToLittle() with appropriate casting.

Definition at line 367 of file posh.cpp.

References POSH_WriteU32ToLittle().

368 {
369  return (posh_s32_t*) POSH_WriteU32ToLittle( dst, (posh_u32_t) value );
370 }
posh_u16_t* POSH_WriteU16ToBig ( void *  dst,
posh_u16_t  value 
)

Writes an unsigned 16-bit value to a big endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian unsigned 16-bit value
Returns
a pointer to the location two bytes after dst
Remarks
does no validation of the inputs

Definition at line 380 of file posh.cpp.

References POSH_BigU16.

Referenced by NetBuffer::addShort(), POSH_WriteS16ToBig(), and s_testSerialization().

381 {
382  posh_u16_t *p16 = (posh_u16_t*) dst;
383 
384  *p16 = POSH_BigU16( value );
385 
386  return p16+2;
387 }
posh_u16_t* POSH_WriteU16ToLittle ( void *  dst,
posh_u16_t  value 
)

Writes an unsigned 16-bit value to a little endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian unsigned 16-bit value
Returns
a pointer to the location two bytes after dst
Remarks
does no validation of the inputs

Definition at line 318 of file posh.cpp.

References POSH_LittleU16.

Referenced by POSH_WriteS16ToLittle(), and s_testSerialization().

319 {
320  posh_u16_t *p16 = (posh_u16_t*) dst;
321 
322  *p16 = POSH_LittleU16( value );
323 
324  return p16+2;
325 }
posh_u32_t* POSH_WriteU32ToBig ( void *  dst,
posh_u32_t  value 
)

Writes an unsigned 32-bit value to a big endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian unsigned 32-bit value
Returns
a pointer to the location four bytes after dst
Remarks
does no validation of the inputs.

Definition at line 411 of file posh.cpp.

References POSH_BigU32.

Referenced by NetBuffer::addUInt32(), POSH_WriteS32ToBig(), and s_testSerialization().

412 {
413  posh_u32_t *p32 = (posh_u32_t*) dst;
414 
415  *p32 = POSH_BigU32( value );
416 
417  return p32+4;
418 }
posh_u32_t* POSH_WriteU32ToLittle ( void *  dst,
posh_u32_t  value 
)

Writes an unsigned 32-bit value to a little endian buffer

Parameters
dst[out]pointer to the destination buffer, may not be NULL
value[in]host-endian signed 32-bit value
Returns
a pointer to the location four bytes after dst
Remarks
does no validation of the inputs.

Definition at line 349 of file posh.cpp.

References POSH_LittleU32.

Referenced by POSH_WriteS32ToLittle(), and s_testSerialization().

350 {
351  posh_u32_t *p32 = (posh_u32_t*) dst;
352 
353  *p32 = POSH_LittleU32( value );
354 
355  return p32+4;
356 }