netmsgs  1.2.2
RoadNarrows Robotics Network Messaging Package
netmsgs.h File Reference

Network Messaging declarations. More...

#include <stdio.h>
#include "rnr/rnrconfig.h"

Go to the source code of this file.

Classes

struct  NMFieldThisPad_T
 
struct  NMFieldThisU8_T
 
struct  NMFieldThisU16_T
 
struct  NMFieldThisU32_T
 
struct  NMFieldThisU64_T
 
struct  NMFieldThisF32_T
 
struct  NMFieldThisF64_T
 
struct  NMFieldThisString_T
 
struct  NMFieldThisVector_T
 
union  NMFieldThis_T
 
struct  _nm_field_def_struct
 
struct  NMVec_T
 
struct  _nm_msg_def_struct
 

Macros

#define NMFTYPE_IS_COMPOUND(ft)   (((ft)==NMFTypeString) || ((ft)==NMFTypeStruct) || ((ft)==NMFTypeVector))
 Returns true if field type is a compoound type. More...
 
#define NMFTYPE_IS_SIMPLE(ft)   (!NMFTYPE_IS_COMPOUND(ft))
 Returns true if field type is a simple type. More...
 
#define NMFVAL_LEN_CHAR   1
 character field length More...
 
#define NMFVAL_LEN_U8   1
 unsigned 8-bit field value length
 
#define NMFVAL_LEN_S8   1
 signed 8-bit field value length
 
#define NMFVAL_LEN_BOOL   1
 boolean field length
 
#define NMFVAL_LEN_U16   2
 unsigned 16-bit field value length
 
#define NMFVAL_LEN_S16   2
 signed 16-bit field value length
 
#define NMFVAL_LEN_U32   4
 unsigned 32-bit field value length
 
#define NMFVAL_LEN_S32   4
 signed 32-bit field value length
 
#define NMFVAL_LEN_U64   8
 unsigned 64-bit field value length
 
#define NMFVAL_LEN_S64   8
 signed 64-bit field value length
 
#define NMFVAL_LEN_F32   4
 32-bit floating-point number field val len
 
#define NMFVAL_LEN_F64   8
 64-bit floating-point number field val len
 
#define NMFVAL_LEN_P32   4
 32-bit pointer field value length
 
#define NMFVAL_LEN_P64   8
 64-bit pointer field value length
 
#define NMFVAL_LEN_BYTE   NMFVAL_LEN_U8
 unsigned char field length
 
#define NMFVAL_LEN_SCHAR   NMFVAL_LEN_S8
 signed char field length
 
#define NMFVAL_LEN_USHORT   NMFVAL_LEN_U16
 unsigned short field length
 
#define NMFVAL_LEN_SHORT   NMFVAL_LEN_S16
 short field length
 
#define NMFVAL_LEN_UINT   NMFVAL_LEN_U32
 signed int field length
 
#define NMFVAL_LEN_INT   NMFVAL_LEN_U32
 unsigned int field length
 
#define NMFVAL_LEN_ULONGLONG   NMFVAL_LEN_U64
 signed long long field length
 
#define NMFVAL_LEN_LONGLONG   NMFVAL_LEN_U64
 unsigned long long field len
 
#define NMFVAL_LEN_FLOAT   NMFVAL_LEN_F32
 float field length
 
#define NMFVAL_LEN_DOUBLE   NMFVAL_LEN_F64
 double field length
 
#define NMFVAL_LEN_POINTER   NMFVAL_LEN_P32
 4-byte void* field length
 
#define NMFVAL_LEN_LONGPOINTER   NMFVAL_LEN_P64
 8-byte void* field length
 
#define NMFVAL_LEN_STRING   0
 char[] variable field length
 
#define NMFVAL_LEN_MAX_STRING   255
 max string length (excluding null)
 
#define NMFVAL_LEN_STRUCT   0
 struct T variable field length
 
#define NMFVAL_LEN_VECTOR   0
 VType[[] variable field length.
 
#define NMFVAL_LEN_MAX_VECTOR   255
 max vector field length (num of items)
 
#define NMFVAL_PAD   ((byte_t)NMFTypePadTr)
 pad field value same as tr id
 
#define NMMSG_ID_NONE   0
 no message id (reserved)
 
#define NMFID_NONE   0
 no field id (reserved)
 
#define NMITV_MSGID_SIZE   2
 2 byte message id size More...
 
#define NMITV_FID_SIZE   1
 1 byte field id size
 
#define NMITV_FTYPE_SIZE   1
 1 byte field type size
 
#define NMITV_FCOUNT_SIZE   1
 1 byte field count size
 
#define NMITV_MSGHDR_SIZE   (NMITV_MSGID_SIZE + NMITV_FCOUNT_SIZE)
 
#define NMITV_FHDR_SIZE_BASE   (NMITV_FID_SIZE + NMITV_FTYPE_SIZE)
 
#define NMITV_FHDR_SIZE_SIMPLE   NMITV_FHDR_SIZE_BASE
 
#define NMITV_FHDR_SIZE_STRING   (NMITV_FHDR_SIZE_BASE + NMITV_FCOUNT_SIZE)
 
#define NMITV_FHDR_SIZE_STRUCT   (NMITV_FHDR_SIZE_BASE + NMITV_FCOUNT_SIZE)
 
#define NMITV_FHDR_SIZE_VECTOR   (NMITV_FHDR_SIZE_BASE + NMITV_FCOUNT_SIZE + NMITV_FTYPE_SIZE)
 
#define NMBITS_HAS_MIN   0x01
 field has a minimum value
 
#define NMBITS_HAS_MAX   0x02
 field has a maximum value
 
#define NMBITS_HAS_CONST   0x04
 field has a constant value
 
#define NM_OK   0
 not an error, success More...
 
#define NM_ECODE_GEN   1
 general, unspecified error
 
#define NM_ECODE_NOMEM   2
 not enough buffer memory available
 
#define NM_ECODE_ARCH_NOTSUP   3
 machine architecture not supported
 
#define NM_ECODE_RANGE   4
 field size or value out-of-range
 
#define NM_ECODE_FTYPE   5
 unknown field type
 
#define NM_ECODE_EMSG   6
 bad message
 
#define NM_ECODE_MSGID   7
 bad/unknown message id
 
#define NM_ECODE_INTERNAL   8
 internal inconsistency or bug
 
#define NM_ECODE_BADEC   9
 internal inconsistency or bug
 
#define NM_ECODE_NUMOF   10
 number of error codes
 

Typedefs

typedef const struct _nm_field_def_structNMFieldDef_P
 msg def struct More...
 
typedef const struct _nm_msg_def_structNMMsgDef_P
 msg def pointer
 
typedef NMMsgDef_P NMFieldThisStruct_T
 
typedef struct _nm_field_def_struct NMFieldDef_T
 
typedef struct _nm_msg_def_struct NMMsgDef_T
 

Enumerations

enum  NMEncoding_T {
  NMEncodingFlat,
  NMEncodingITV,
  NMEncodingCLI,
  NMEncodingNumOf
}
 
enum  NMEndian_T {
  NMEndianBig,
  NMEndianLittle,
  NMEndianNative
}
 
enum  NMFType_T {
  NMFTypeNone = 0,
  NMFTypePadTr = 0,
  NMFTypeBool = '?',
  NMFTypeU8 = 'B',
  NMFTypeByte = 'B',
  NMFTypeF64 = 'F',
  NMFTypeDouble = 'F',
  NMFTypeU16 = 'H',
  NMFTypeUShort = 'H',
  NMFTypeU32 = 'I',
  NMFTypeUInt = 'I',
  NMFTypeP64 = 'P',
  NMFTypeLongPointer = 'P',
  NMFTypeU64 = 'Q',
  NMFTypeULongLong = 'Q',
  NMFTypeVector = '[',
  NMFTypeS8 = 'b',
  NMFTypeSChar = 'b',
  NMFTypeChar = 'c',
  NMFTypeF32 = 'f',
  NMFTypeFloat = 'f',
  NMFTypeS16 = 'h',
  NMFTypeShort = 'h',
  NMFTypeS32 = 'i',
  NMFTypeInt = 'i',
  NMFTypeP32 = 'p',
  NMFTypePointer = 'p',
  NMFTypeS64 = 'q',
  NMFTypeLongLong = 'q',
  NMFTypeString = 's',
  NMFTypePad = 'x',
  NMFTypeStruct = '{',
  NMFTypeNumOf = 18
}
 

Functions

const char * nmStrError (int ecode)
 Get the error string describing the BotSense error code. More...
 
void nmPrintBuf (FILE *fp, const char *sPreface, byte_t buf[], size_t uCount, size_t uNLFreq, uint_t uCol)
 Pretty print buffer to opened file stream. More...
 
void nmPrintBits (FILE *fp, const char *sPreface, ulonglong_t uVal, uint_t uMsb, uint_t uCnt)
 Pretty print bits in value. More...
 
size_t nmGetFieldValSize (NMFType_T eFType)
 Get the field value byte size. More...
 
const NMFieldDef_TnmFindFieldDef (const NMMsgDef_T *pMsgDef, byte_t byFId)
 Find the field definition in the message definition, given the field id. More...
 
int nmPackU8 (byte_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned 8-bit byte into the message buffer. More...
 
int nmPackU16 (ushort_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned 16-bit integer into the message buffer. More...
 
int nmPackU32 (uint_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned 32-bit integer into the message buffer. More...
 
int nmPackU64 (ulonglong_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned 64-bit integer into the message buffer. More...
 
int nmPackS64 (long long val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an signed 64-bit integer into the message buffer. More...
 
int nmPackF32 (float val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a 32-bit float into the message buffer. More...
 
int nmPackF64 (double val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a 64-bit float into the message buffer. More...
 
int nmPackP32 (void *val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a 32-bit pointer into the message buffer. More...
 
int nmPackP64 (void *val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a 64-bit pointer into the message buffer. More...
 
int nmPackBuf (byte_t bufSrc[], size_t uCount, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a byte buffer into the message buffer. More...
 
INLINE_IN_H int nmPackS8 (signed char val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a signed 8-bit byte into the message buffer. More...
 
INLINE_IN_H int nmPackS16 (short val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a signed 16-bit integer into the message buffer. More...
 
INLINE_IN_H int nmPackS32 (int val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a signed 32-bit integer into the message buffer. More...
 
INLINE_IN_H int nmPackByte (byte_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a one byte value into the message buffer. More...
 
INLINE_IN_H int nmPackSChar (signed char val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a signed char integer value into the message buffer. More...
 
INLINE_IN_H int nmPackChar (char val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a 8-bit ASCII character into the message buffer. More...
 
INLINE_IN_H int nmPackBool (bool_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a boolean value into the message buffer. More...
 
INLINE_IN_H int nmPackUShort (ushort_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned short integer into the message buffer. More...
 
INLINE_IN_H int nmPackShort (short val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an signed short integer into the message buffer. More...
 
INLINE_IN_H int nmPackUInt (uint_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned int integer into the message buffer. More...
 
INLINE_IN_H int nmPackInt (int val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an signed int integer into the message buffer. More...
 
INLINE_IN_H int nmPackULong (ulong_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned long integer into the message buffer. More...
 
INLINE_IN_H int nmPackLong (long val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an signed long integer into the message buffer. More...
 
INLINE_IN_H int nmPackULongLong (ulonglong_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an unsigned long long integer into the message buffer. More...
 
INLINE_IN_H int nmPackLongLong (long long val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an signed long long integer into the message buffer. More...
 
INLINE_IN_H int nmPackPointer (void *val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack a (overloaded) void* pointer into the message buffer. More...
 
int nmUnpackU8 (byte_t buf[], size_t bufSize, byte_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned 8-bit byte from the message buffer. More...
 
int nmUnpackU16 (byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned 16-bit integer from the message buffer. More...
 
int nmUnpackU32 (byte_t buf[], size_t bufSize, uint_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned 32-bit integer from the message buffer. More...
 
int nmUnpackU64 (byte_t buf[], size_t bufSize, ulonglong_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned 64-bit integer from the message buffer. More...
 
int nmUnpackS64 (byte_t buf[], size_t bufSize, long long *pVal, NMEndian_T eEndian)
 Unpack an signed 64-bit integer from the message buffer. More...
 
int nmUnpackF32 (byte_t buf[], size_t bufSize, float *pVal, NMEndian_T eEndian)
 Unpack a 32-bit float from the message buffer. More...
 
int nmUnpackF64 (byte_t buf[], size_t bufSize, double *pVal, NMEndian_T eEndian)
 Unpack a 64-bit float from the message buffer. More...
 
int nmUnpackP32 (byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian)
 Unpack a 32-bit pointer from the message buffer. More...
 
int nmUnpackP64 (byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian)
 Unpack a 64-bit pointer from the message buffer. More...
 
int nmUnpackBuf (byte_t buf[], size_t bufSize, byte_t bufDst[], size_t uCount, NMEndian_T eEndian)
 Unpack a byte buffer from the message buffer. More...
 
INLINE_IN_H int nmUnpackS8 (byte_t buf[], size_t bufSize, signed char *pVal, NMEndian_T eEndian)
 Unpack a signed 8-bit byte from the message buffer. More...
 
INLINE_IN_H int nmUnpackS16 (byte_t buf[], size_t bufSize, short *pVal, NMEndian_T eEndian)
 Unpack a signed 16-bit integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackS32 (byte_t buf[], size_t bufSize, int *pVal, NMEndian_T eEndian)
 Unpack a signed 32-bit integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackByte (byte_t buf[], size_t bufSize, byte_t *pVal, NMEndian_T eEndian)
 Unpack one byte from the message buffer. More...
 
INLINE_IN_H int nmUnpackSChar (byte_t buf[], size_t bufSize, signed char *pVal, NMEndian_T eEndian)
 Unpack an signed short integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackChar (byte_t buf[], size_t bufSize, char *pVal, NMEndian_T eEndian)
 Unpack an 8-bit ASCII character from the message buffer. More...
 
INLINE_IN_H int nmUnpackBool (byte_t buf[], size_t bufSize, bool_t *pVal, NMEndian_T eEndian)
 Unpack a boolean value from the message buffer. More...
 
INLINE_IN_H int nmUnpackUShort (byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned short integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackShort (byte_t buf[], size_t bufSize, short *pVal, NMEndian_T eEndian)
 Unpack an signed short integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackUInt (byte_t buf[], size_t bufSize, uint_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned int integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackInt (byte_t buf[], size_t bufSize, int *pVal, NMEndian_T eEndian)
 Unpack an signed int integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackULong (byte_t buf[], size_t bufSize, ulong_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned long integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackLong (byte_t buf[], size_t bufSize, long *pVal, NMEndian_T eEndian)
 Unpack an signed long integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackULongLong (byte_t buf[], size_t bufSize, ulonglong_t *pVal, NMEndian_T eEndian)
 Unpack an unsigned long long integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackLongLong (byte_t buf[], size_t bufSize, long long *pVal, NMEndian_T eEndian)
 Unpack an signed long long integer from the message buffer. More...
 
INLINE_IN_H int nmUnpackPointer (byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian)
 Unpack a (overloaded)void* pointer from the message buffer. More...
 
int nmPackITVMsg (const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an ITV message. More...
 
int nmPackITVMsgDebug (const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an ITV message, tracing message packing to stderr. More...
 
int nmUnpackITVMsg (const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, void *pStruct, NMEndian_T eEndian)
 Unpack a ITV message. More...
 
int nmUnpackITVMsgDebug (const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, void *pStruct, NMEndian_T eEndian)
 Unpack a ITV message, tracing unpacking to stderr. More...
 
uint_t nmGetITVMsgId (byte_t buf[], size_t uMsgLen, NMEndian_T eEndian)
 Get ITV message id from input buffer. More...
 
int nmPackFlatMsg (const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an Flat message. More...
 
int nmPackFlatMsgDebug (const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
 Pack an Flat message, tracing message packing to stderr. More...
 
int nmUnpackFlatMsg (const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, void *pStruct, NMEndian_T eEndian)
 Unpack a Flat message. More...
 
int nmUnpackFlatMsgDebug (const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, void *pStruct, NMEndian_T eEndian)
 Unpack a Flat message, tracing unpacking to stderr. More...
 

Detailed Description

Network Messaging declarations.

LastChangedDate
2010-07-31 08:48:56 -0600 (Sat, 31 Jul 2010)
Rev
521
Note
This file must be swig-able to generate a python extension module.
Author
Robin Knight (robin.nosp@m..kni.nosp@m.ght@r.nosp@m.oadn.nosp@m.arrow.nosp@m.s.co.nosp@m.m)

Definition in file netmsgs.h.

Macro Definition Documentation

#define NMFTYPE_IS_COMPOUND (   ft)    (((ft)==NMFTypeString) || ((ft)==NMFTypeStruct) || ((ft)==NMFTypeVector))

Returns true if field type is a compoound type.

Parameters
ftField type.

Definition at line 156 of file netmsgs.h.

#define NMFTYPE_IS_SIMPLE (   ft)    (!NMFTYPE_IS_COMPOUND(ft))

Returns true if field type is a simple type.

Parameters
ftField type.

Definition at line 164 of file netmsgs.h.

Referenced by nmPackFlatVector(), nmPackITVVector(), and nmUnpackITVVector().

#define NMFVAL_LEN_CHAR   1

character field length

Message packed field value lengths in bytes.

Definition at line 171 of file netmsgs.h.

#define NMITV_FHDR_SIZE_BASE   (NMITV_FID_SIZE + NMITV_FTYPE_SIZE)

number of bytes in header to identify and quatify field (fid, ftype)

Definition at line 225 of file netmsgs.h.

Referenced by nmUnpackITVStream().

#define NMITV_FHDR_SIZE_STRING   (NMITV_FHDR_SIZE_BASE + NMITV_FCOUNT_SIZE)

number of bytes in string field header (fid, ftype, count)

Definition at line 231 of file netmsgs.h.

Referenced by nmPackITVHdrSimple(), nmPackITVHdrString(), and nmUnpackITVString().

#define NMITV_FHDR_SIZE_STRUCT   (NMITV_FHDR_SIZE_BASE + NMITV_FCOUNT_SIZE)

number of bytes in struct field header (fid, ftype, count)

Definition at line 234 of file netmsgs.h.

Referenced by nmPackITVHdrStruct(), and nmUnpackITVStruct().

#define NMITV_FHDR_SIZE_VECTOR   (NMITV_FHDR_SIZE_BASE + NMITV_FCOUNT_SIZE + NMITV_FTYPE_SIZE)

number of bytes in vector field header (fid, ftype, count, vtype)

Definition at line 237 of file netmsgs.h.

Referenced by nmPackITVHdrVector(), and nmUnpackITVVector().

#define NMITV_MSGHDR_SIZE   (NMITV_MSGID_SIZE + NMITV_FCOUNT_SIZE)

message leading number of bytes for message header (msgid, fcount)

Definition at line 222 of file netmsgs.h.

Referenced by nmGetITVMsgId(), nmPackITVMsg(), nmPackITVMsgDebug(), nmUnpackITVMsg(), and nmUnpackITVMsgDebug().

#define NMITV_MSGID_SIZE   2

2 byte message id size

ITV Messge and Field encodings/decodings.

Definition at line 216 of file netmsgs.h.

Typedef Documentation

typedef const struct _nm_field_def_struct* NMFieldDef_P

msg def struct

field def pointer

Definition at line 250 of file netmsgs.h.

Message Field Definition Type

This strcuture field definition specific information. (equivalent to a submessage)

Definition at line 347 of file netmsgs.h.

Message Definition Type

Enumeration Type Documentation

Message Encoding Type Enumeration

Enumerator
NMEncodingFlat 

flat (no field header and fixed size) encoding

NMEncodingITV 

id-type-value encoding

NMEncodingCLI 

command-line interface encoding (future)

NMEncodingNumOf 

number of different encodings supported

Definition at line 89 of file netmsgs.h.

90 {
91  NMEncodingFlat, ///< flat (no field header and fixed size) encoding
92  NMEncodingITV, ///< id-type-value encoding
93  NMEncodingCLI, ///< command-line interface encoding (future)
94  NMEncodingNumOf ///< number of different encodings supported
95 } NMEncoding_T;
flat (no field header and fixed size) encoding
Definition: netmsgs.h:91
command-line interface encoding (future)
Definition: netmsgs.h:93
id-type-value encoding
Definition: netmsgs.h:92
NMEncoding_T
Definition: netmsgs.h:89
number of different encodings supported
Definition: netmsgs.h:94
enum NMEndian_T

Message Byte Ordering Type Enumeration

Enumerator
NMEndianBig 

Most Significant Byte first.

NMEndianLittle 

Least Significant Byte first.

NMEndianNative 

native processor order

Definition at line 100 of file netmsgs.h.

101 {
102  NMEndianBig, ///< Most Significant Byte first
103  NMEndianLittle, ///< Least Significant Byte first
104  NMEndianNative ///< native processor order
105 } NMEndian_T;
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
NMEndian_T
Definition: netmsgs.h:100
Least Significant Byte first.
Definition: netmsgs.h:103
enum NMFType_T

Message Field Type Code Enumeration

Enumerator
NMFTypeNone 

no field type -

NMFTypePadTr 

translated pad type for packed stream

NMFTypeBool 

8-bit bool 0/1 bool_t

NMFTypeU8 

unsigned 8-bit integer unsigned char

NMFTypeByte 

U8 alias.

NMFTypeF64 

64-bit IEEE 754 FPN double

NMFTypeDouble 

F64 alias.

NMFTypeU16 

unsigned 16-bit integer unsigned short

NMFTypeUShort 

U16 alias.

NMFTypeU32 

unsigned 32-bit integer unsigned int

NMFTypeUInt 

U32 alias.

NMFTypeP64 

64-bit pointer (overloaded) void*

NMFTypeLongPointer 

P64 alias.

NMFTypeU64 

unsigned 64-bit integer unsigned long long

NMFTypeULongLong 

U64 alias.

NMFTypeVector 

one dimensional array VType[]

NMFTypeS8 

signed 8-bit integer signed char

NMFTypeSChar 

S8 alias.

NMFTypeChar 

8-bit ASCII characters char

NMFTypeF32 

32-bit IEEE 754 FPN float

NMFTypeFloat 

F32 alias.

NMFTypeS16 

signed 16-bit integer short

NMFTypeShort 

S16 alias.

NMFTypeS32 

signed 32-bit integer int

NMFTypeInt 

S32 alias.

NMFTypeP32 

32-bit pointer (overloaded) void*

NMFTypePointer 

P32 alias.

NMFTypeS64 

signed 64-bit integer long long

NMFTypeLongLong 

S64 alias.

NMFTypeString 

string char[]

NMFTypePad 

pad internal field type

NMFTypeStruct 

structure struct T

NMFTypeNumOf 

number of

Definition at line 110 of file netmsgs.h.

111 {
112  NMFTypeNone = 0, ///< no field type -
113  NMFTypePadTr = 0, ///< translated pad type for packed stream
114 
115  // enum value message field C data type
116  // ---- ----- ------------- ------------
117  NMFTypeBool = '?', ///< 8-bit bool 0/1 bool_t
118  NMFTypeU8 = 'B', ///< unsigned 8-bit integer unsigned char
119  NMFTypeByte = 'B', ///< U8 alias
120  NMFTypeF64 = 'F', ///< 64-bit IEEE 754 FPN double
121  NMFTypeDouble = 'F', ///< F64 alias
122  NMFTypeU16 = 'H', ///< unsigned 16-bit integer unsigned short
123  NMFTypeUShort = 'H', ///< U16 alias
124  NMFTypeU32 = 'I', ///< unsigned 32-bit integer unsigned int
125  NMFTypeUInt = 'I', ///< U32 alias
126  NMFTypeP64 = 'P', ///< 64-bit pointer (overloaded) void*
127  NMFTypeLongPointer = 'P', ///< P64 alias
128  NMFTypeU64 = 'Q', ///< unsigned 64-bit integer unsigned long long
129  NMFTypeULongLong = 'Q', ///< U64 alias
130  NMFTypeVector = '[', ///< one dimensional array VType[]
131  NMFTypeS8 = 'b', ///< signed 8-bit integer signed char
132  NMFTypeSChar = 'b', ///< S8 alias
133  NMFTypeChar = 'c', ///< 8-bit ASCII characters char
134  NMFTypeF32 = 'f', ///< 32-bit IEEE 754 FPN float
135  NMFTypeFloat = 'f', ///< F32 alias
136  NMFTypeS16 = 'h', ///< signed 16-bit integer short
137  NMFTypeShort = 'h', ///< S16 alias
138  NMFTypeS32 = 'i', ///< signed 32-bit integer int
139  NMFTypeInt = 'i', ///< S32 alias
140  NMFTypeP32 = 'p', ///< 32-bit pointer (overloaded) void*
141  NMFTypePointer = 'p', ///< P32 alias
142  NMFTypeS64 = 'q', ///< signed 64-bit integer long long
143  NMFTypeLongLong = 'q', ///< S64 alias
144  NMFTypeString = 's', ///< string char[]
145  NMFTypePad = 'x', ///< pad internal field type
146  NMFTypeStruct = '{', ///< structure struct T
147 
148  NMFTypeNumOf = 18 ///< number of
149 } NMFType_T;
64-bit IEEE 754 FPN double
Definition: netmsgs.h:120
S8 alias.
Definition: netmsgs.h:132
unsigned 8-bit integer unsigned char
Definition: netmsgs.h:118
32-bit IEEE 754 FPN float
Definition: netmsgs.h:134
unsigned 64-bit integer unsigned long long
Definition: netmsgs.h:128
structure struct T
Definition: netmsgs.h:146
signed 32-bit integer int
Definition: netmsgs.h:138
string char[]
Definition: netmsgs.h:144
U16 alias.
Definition: netmsgs.h:123
S64 alias.
Definition: netmsgs.h:143
U64 alias.
Definition: netmsgs.h:129
8-bit ASCII characters char
Definition: netmsgs.h:133
translated pad type for packed stream
Definition: netmsgs.h:113
signed 64-bit integer long long
Definition: netmsgs.h:142
S32 alias.
Definition: netmsgs.h:139
8-bit bool 0/1 bool_t
Definition: netmsgs.h:117
32-bit pointer (overloaded) void*
Definition: netmsgs.h:140
64-bit pointer (overloaded) void*
Definition: netmsgs.h:126
NMFType_T
Definition: netmsgs.h:110
signed 8-bit integer signed char
Definition: netmsgs.h:131
P32 alias.
Definition: netmsgs.h:141
F32 alias.
Definition: netmsgs.h:135
one dimensional array VType[]
Definition: netmsgs.h:130
no field type -
Definition: netmsgs.h:112
unsigned 32-bit integer unsigned int
Definition: netmsgs.h:124
pad internal field type
Definition: netmsgs.h:145
U32 alias.
Definition: netmsgs.h:125
U8 alias.
Definition: netmsgs.h:119
F64 alias.
Definition: netmsgs.h:121
S16 alias.
Definition: netmsgs.h:137
number of
Definition: netmsgs.h:148
P64 alias.
Definition: netmsgs.h:127
unsigned 16-bit integer unsigned short
Definition: netmsgs.h:122
signed 16-bit integer short
Definition: netmsgs.h:136

Function Documentation

const NMFieldDef_T* nmFindFieldDef ( const NMMsgDef_T pMsgDef,
byte_t  byFId 
)

Find the field definition in the message definition, given the field id.

Parameters
pMsgDefPointer to message definition.
byFIdField Id.
Returns
If the field definition is found, then the pointer to the field definition is returned. Else NULL is return.

Definition at line 235 of file nmLibUtils.c.

References _nm_field_def_struct::m_eFId, _nm_msg_def_struct::m_pFields, and _nm_msg_def_struct::m_uCount.

Referenced by nmUnpackITVStream().

236 {
237  size_t i;
238 
239  for(i=0; i<pMsgDef->m_uCount; ++i)
240  {
241  if( pMsgDef->m_pFields[i].m_eFId == byFId )
242  {
243  return &(pMsgDef->m_pFields[i]);
244  }
245  }
246 
247  return NULL;
248 }
size_t m_uCount
number of message fields
Definition: netmsgs.h:408
const NMFieldDef_T * m_pFields
pointer to array of msg field definitions
Definition: netmsgs.h:409
uint_t m_eFId
filed id (message/struct unique)
Definition: netmsgs.h:382
size_t nmGetFieldValSize ( NMFType_T  eFType)

Get the field value byte size.

Parameters
eFTypeField type.
Returns
Returns field value byte size. Returns 0 if field type is unknown or is variable in length.

Definition at line 209 of file nmLibUtils.c.

References NMFValLenLookupTbl, NMHashFType(), and NMHashNoIdx.

210 {
211  int idx;
212 
213  idx = NMHashFType(eFType);
214 
215  if( (idx != NMHashNoIdx) && (idx < arraysize(NMFValLenLookupTbl)) )
216  {
217  return NMFValLenLookupTbl[idx];
218  }
219  else
220  {
221  return (size_t)0;
222  }
223 }
const int NMHashNoIdx
hash no index value
static size_t NMFValLenLookupTbl[]
Definition: nmLibUtils.c:90
INLINE_IN_H int NMHashFType(NMFType_T eFType)
Field Type to Index hash function.
uint_t nmGetITVMsgId ( byte_t  buf[],
size_t  uMsgLen,
NMEndian_T  eEndian 
)

Get ITV message id from input buffer.

Parameters
[in]bufInput message buffer.
uMsgLenLength of message (bytes) in input buffer.
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns unpacked message id.
On error, returns NMMSG_ID_NONE (0).

Definition at line 2482 of file nmLibPackITV.c.

References NMITV_MSGHDR_SIZE, NMMSG_ID_NONE, and nmUnpackU16().

Referenced by nmUnpackPointer().

2483 {
2484  ushort_t eMsgId; // message id in buffer
2485  int n;
2486 
2487  // too small
2488  if( uMsgLen < NMITV_MSGHDR_SIZE )
2489  {
2490  return (uint_t)NMMSG_ID_NONE;
2491  }
2492 
2493  // unpack message id
2494  else if( (n = nmUnpackU16(buf, uMsgLen, &eMsgId, eEndian)) < 0 )
2495  {
2496  return (uint_t)NMMSG_ID_NONE;
2497  }
2498 
2499  else
2500  {
2501  return (uint_t)eMsgId;
2502  }
2503 }
int nmUnpackU16(byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 16-bit integer from the message buffer.
Definition: nmLibPack.c:1256
#define NMITV_MSGHDR_SIZE
Definition: netmsgs.h:222
#define NMMSG_ID_NONE
no message id (reserved)
Definition: netmsgs.h:210
INLINE_IN_H int nmPackBool ( bool_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a boolean value into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 564 of file netmsgs.h.

References nmPackU8().

Referenced by nmPackFlatBool(), and nmPackITVBool().

566 {
567  val &= 0xff; // clear unused upper bits
568  return nmPackU8((byte_t)val, buf, bufSize, eEndian);
569 }
int nmPackU8(byte_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 8-bit byte into the message buffer.
Definition: nmLibPack.c:745
int nmPackBuf ( byte_t  bufSrc[],
size_t  uCount,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a byte buffer into the message buffer.

The source and message buffer memory areas can overlap.

Note
The buffer is always packed in sequential order ignoring the byte order parameter.
Parameters
[in]bufSrcSource buffer.
uCountNumber of bytes to copy.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1215 of file nmLibPack.c.

References _NM_CHK_MEM.

1220 {
1221  _NM_CHK_MEM(bufSize, uCount);
1222 
1223  // safe copy
1224  memmove(buf, bufSrc, uCount);
1225 
1226  return (int)uCount;
1227 }
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
INLINE_IN_H int nmPackByte ( byte_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a one byte value into the message buffer.

Alias for nmPackU8().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 526 of file netmsgs.h.

References nmPackU8().

528 {
529  return nmPackU8((byte_t)val, buf, bufSize, eEndian);
530 }
int nmPackU8(byte_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 8-bit byte into the message buffer.
Definition: nmLibPack.c:745
INLINE_IN_H int nmPackChar ( char  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a 8-bit ASCII character into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 552 of file netmsgs.h.

References nmPackU8().

554 {
555  return nmPackU8((byte_t)val, buf, bufSize, eEndian);
556 }
int nmPackU8(byte_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 8-bit byte into the message buffer.
Definition: nmLibPack.c:745
int nmPackF32 ( float  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a 32-bit float into the message buffer.

The IEEE 754 32-bit format is used with both the big and little endian byte orders.

Note
On some machines, while integers were represented in little-endian form, floating point numbers were represented in big-endian form. Because there are many floating point formats, and a lack of a standard network representation, no standard for transferring floating point values has been made - Wikipedia.
Todo:
Detect non-IEEE 754 formats and convert to IEEE 754 prior to packing.
Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 957 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, IEEE754_F32_EXPONENT_MASK, IEEE754_F32_EXPONENT_SHIFT, IEEE754_F32_MANTISSA_MASK, IEEE754_F32_MANTISSA_SHIFT, IEEE754_F32_SIGN_MASK, IEEE754_F32_SIGN_SHIFT, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_F32, PACKBIG, PACKLITTLE, and PACKNATIVE.

Referenced by nmPackFlatF32(), and nmPackITVF32().

958 {
959  static size_t fvalLen = NMFVAL_LEN_F32; // message field value length
960 
961  union ieee754_float f; // 4 byte floating-point number
962  uint_t uBits; // bits
963 
964  _NM_CHK_MEM(bufSize, fvalLen);
965  _NM_CHK_ARCH(val, fvalLen);
966 
967  f.f = val;
968 
969  uBits = (uint_t)((f.ieee.negative & IEEE754_F32_SIGN_MASK)
971  uBits |= (uint_t)((f.ieee.exponent & IEEE754_F32_EXPONENT_MASK)
973  uBits |= (uint_t)((f.ieee.mantissa & IEEE754_F32_MANTISSA_MASK)
975 
976  switch( eEndian )
977  {
978  case NMEndianLittle:
979  PACKLITTLE(uBits, buf);
980  break;
981  case NMEndianNative:
982  PACKNATIVE(f.f, buf);
983  break;
984  case NMEndianBig:
985  default:
986  PACKBIG(uBits, buf);
987  break;
988  }
989 
990  return (int)fvalLen;
991 }
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
#define IEEE754_F32_EXPONENT_SHIFT
f32 exponent shift
Definition: nmLibPack.c:518
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define PACKBIG(val, buf)
Pack an element into the message buffer in big-endian byte order.
Definition: nmLibPack.c:397
#define PACKLITTLE(val, buf)
Pack an element into the message buffer in little-endian byte order.
Definition: nmLibPack.c:413
#define NMFVAL_LEN_F32
32-bit floating-point number field val len
Definition: netmsgs.h:181
#define IEEE754_F32_SIGN_MASK
f32 sign mask
Definition: nmLibPack.c:517
#define PACKNATIVE(val, buf)
Pack an element into the message buffer in native byte order.
Definition: nmLibPack.c:216
#define IEEE754_F32_EXPONENT_MASK
f32 exponent mask
Definition: nmLibPack.c:519
#define IEEE754_F32_SIGN_SHIFT
f32 sign shift
Definition: nmLibPack.c:516
#define IEEE754_F32_MANTISSA_MASK
f32 mantissa mask
Definition: nmLibPack.c:521
Least Significant Byte first.
Definition: netmsgs.h:103
#define IEEE754_F32_MANTISSA_SHIFT
f32 mantissa shift
Definition: nmLibPack.c:520
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmPackF64 ( double  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a 64-bit float into the message buffer.

The IEEE 754 64-bit format is used with both the big and little endian byte orders. If the machine architecture only supports 32-bit doubles, then a conversion to 64-bit representation is performed first.

Note
On some machines, while integers were represented in little-endian form, floating point numbers were represented in big-endian form. Because there are many floating point formats, and a lack of a standard network representation, no standard for transferring floating point values has been made - Wikipedia.
Todo:
Detect non-IEEE 754 formats and convert to IEEE 754 prior to packing.
Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1013 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, IEEE754_F32_F64_MANTISSA0_SHIFT, IEEE754_F32_F64_MANTISSA1_MASK, IEEE754_F32_F64_MANTISSA1_SHIFT, ieee754_f32_is_inf(), ieee754_f32_is_nan(), ieee754_f32_is_zero(), IEEE754_F64_EXPONENT_MASK, IEEE754_F64_EXPONENT_SHIFT, IEEE754_F64_Inf, IEEE754_F64_MANTISSA0_MASK, IEEE754_F64_MANTISSA0_SHIFT, IEEE754_F64_MANTISSA1_MASK, IEEE754_F64_MANTISSA1_SHIFT, IEEE754_F64_NaN, IEEE754_F64_SIGN_MASK, IEEE754_F64_SIGN_SHIFT, IEEE754_F64_Zero, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_F32, NMFVAL_LEN_F64, PACK64BIG, PACK64LITTLE, and PACK64NATIVE.

Referenced by nmPackFlatF64(), and nmPackITVF64().

1014 {
1015  static size_t fvalLen = NMFVAL_LEN_F64; // message field value length
1016 
1017  union ieee754_float f; // 4-byte floating-point number
1018  union ieee754_double d; // 8-byte floating-point number
1019  uint_t uMSB; // Most Signifcant Bytes
1020  uint_t uLSB; // Least Signifcant Bytes
1021 
1022  _NM_CHK_MEM(bufSize, fvalLen);
1023 
1024  // 8-byte double
1025  if( sizeof(double) == fvalLen )
1026  {
1027  d.d = val;
1028  }
1029 
1030  // 4-byte double
1031  else
1032  {
1033  _NM_CHK_ARCH(val, (size_t)NMFVAL_LEN_F32);
1034 
1035  f.f = (float)val;
1036 
1037  // special infinity cases
1038  if( ieee754_f32_is_inf(f) )
1039  {
1040  d = IEEE754_F64_Inf;
1041  }
1042 
1043  // special zero cases
1044  else if( ieee754_f32_is_zero(f) )
1045  {
1046  d = IEEE754_F64_Zero;
1047  }
1048 
1049  // special Not-a-Number case
1050  else if( ieee754_f32_is_nan(f) )
1051  {
1052  d = IEEE754_F64_NaN;
1053  }
1054 
1055  // "normal" floating-point numbers
1056  else
1057  {
1058  d.ieee.exponent = (f.ieee.exponent + (uint_t)IEEE754_DOUBLE_BIAS
1059  - (uint_t)IEEE754_FLOAT_BIAS)
1061  d.ieee.mantissa0 = ((uint_t)(f.ieee.mantissa
1062  >> (uint_t)IEEE754_F32_F64_MANTISSA0_SHIFT))
1064  d.ieee.mantissa1 = (((uint_t)(f.ieee.mantissa))
1067  }
1068 
1069  // preserve the sign
1070  d.ieee.negative = f.ieee.negative;
1071  }
1072 
1073  //
1074  // Stuff the bits into two 4-byte unsigned integers.
1075  //
1076  uMSB = (uint_t)((d.ieee.negative & IEEE754_F64_SIGN_MASK)
1078  uMSB |= (uint_t)((d.ieee.exponent & IEEE754_F64_EXPONENT_MASK)
1080  uMSB |= (uint_t)((d.ieee.mantissa0 & IEEE754_F64_MANTISSA0_MASK)
1082  uLSB = (uint_t)((d.ieee.mantissa1 & IEEE754_F64_MANTISSA1_MASK)
1084 
1085  switch( eEndian )
1086  {
1087  case NMEndianLittle:
1088  PACK64LITTLE(uMSB, uLSB, buf);
1089  break;
1090  case NMEndianNative:
1091  PACK64NATIVE(uMSB, uLSB, buf);
1092  break;
1093  case NMEndianBig:
1094  default:
1095  PACK64BIG(uMSB, uLSB, buf);
1096  break;
1097  }
1098 
1099  return (int)fvalLen;
1100 }
static bool_t ieee754_f32_is_zero(union ieee754_float f)
Test if 32-bit floating-point number is &plusmn; 0.0.
Definition: nmLibPack.c:675
#define IEEE754_F32_F64_MANTISSA1_SHIFT
lsb mantissa shift
Definition: nmLibPack.c:544
#define IEEE754_F64_MANTISSA0_SHIFT
f64 msb mantissa shift
Definition: nmLibPack.c:535
static const union ieee754_double IEEE754_F64_NaN
Definition: nmLibPack.c:576
#define IEEE754_F64_SIGN_SHIFT
f64 sign shift
Definition: nmLibPack.c:531
#define IEEE754_F64_MANTISSA1_MASK
f64 lsb mantissa mask
Definition: nmLibPack.c:538
static const union ieee754_double IEEE754_F64_Inf
Definition: nmLibPack.c:597
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
Most Significant Byte first.
Definition: netmsgs.h:102
#define NMFVAL_LEN_F64
64-bit floating-point number field val len
Definition: netmsgs.h:182
#define PACK64BIG(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in big-endian byte order.
Definition: nmLibPack.c:436
#define IEEE754_F64_MANTISSA0_MASK
f64 msb mantissa mask
Definition: nmLibPack.c:536
native processor order
Definition: netmsgs.h:104
#define IEEE754_F64_EXPONENT_MASK
f64 exponent mask
Definition: nmLibPack.c:534
#define NMFVAL_LEN_F32
32-bit floating-point number field val len
Definition: netmsgs.h:181
#define IEEE754_F64_EXPONENT_SHIFT
f64 exponent shift
Definition: nmLibPack.c:533
#define PACK64LITTLE(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in little-endian byte order.
Definition: nmLibPack.c:477
static bool_t ieee754_f32_is_nan(union ieee754_float f)
Test if 32-bit floating-point number is a NaN.
Definition: nmLibPack.c:631
#define IEEE754_F32_F64_MANTISSA1_MASK
lsb mantissa mask
Definition: nmLibPack.c:545
static const union ieee754_double IEEE754_F64_Zero
Definition: nmLibPack.c:618
#define PACK64NATIVE(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in native byte order.
Definition: nmLibPack.c:238
static bool_t ieee754_f32_is_inf(union ieee754_float f)
Test if 32-bit floating-point number is &plusmn; infinity.
Definition: nmLibPack.c:653
Least Significant Byte first.
Definition: netmsgs.h:103
#define IEEE754_F64_MANTISSA1_SHIFT
f64 lsb mantissa shift
Definition: nmLibPack.c:537
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
#define IEEE754_F64_SIGN_MASK
f64 sign mask
Definition: nmLibPack.c:532
#define IEEE754_F32_F64_MANTISSA0_SHIFT
msb mantissa shift
Definition: nmLibPack.c:543
int nmPackFlatMsg ( const NMMsgDef_T pMsgDef,
void *  pStruct,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an Flat message.

Parameters
pMsgDefPointer to message definition.
[in]pStructPointer to the associated, populated message structure.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1417 of file nmLibPackFlat.c.

References NMCtl_T::m_bNoHdr, NMCTL_INIT_DECL, and nmPackFlatStream().

Referenced by nmUnpackPointer().

1422 {
1423  NMCtl_T ctl = NMCTL_INIT_DECL;
1424  int n; // byte count/error code
1425 
1426  ctl.m_bNoHdr = true;
1427 
1428  // pack stream
1429  n = nmPackFlatStream(pMsgDef, pStruct, buf, bufSize, eEndian, &ctl);
1430 
1431  return n;
1432 }
byte_t m_bNoHdr
do [not] include field header in byte stream
static int nmPackFlatStream(const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a Flat message.
#define NMCTL_INIT_DECL
Default Internal control declartion list.
Internal Control Structure.
int nmPackFlatMsgDebug ( const NMMsgDef_T pMsgDef,
void *  pStruct,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an Flat message, tracing message packing to stderr.

Parameters
pMsgDefPointer to message definition.
[in]pStructPointer to the associated, populated message structure.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1446 of file nmLibPackFlat.c.

References NMCtl_T::m_bNoHdr, NMCtl_T::m_bTrace, _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_sMsgName, _nm_msg_def_struct::m_uCount, NMCTL_INIT_DECL, nmPackFlatStream(), and nmPrintBuf().

Referenced by nmUnpackPointer().

1451 {
1452  NMCtl_T ctl = NMCTL_INIT_DECL;
1453  int n; // byte count/error code
1454 
1455  ctl.m_bNoHdr = true;
1456  ctl.m_bTrace = true;
1457 
1458  // trace
1459  fprintf(stderr, "\n--- Packing Flat Message %s(%u): field_count=%zu\n",
1460  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, pMsgDef->m_uCount);
1461 
1462  // pack stream
1463  n = nmPackFlatStream(pMsgDef, pStruct, buf, bufSize, eEndian, &ctl);
1464 
1465  // trace final buffer
1466  if( n > 0 )
1467  {
1468  fprintf(stderr, "Output Buffer (%zu bytes):\n", (size_t)n);
1469  nmPrintBuf(stderr, NULL, buf, (size_t)n, 16, 0);
1470  fprintf(stderr, "\n");
1471  }
1472 
1473  return n;
1474 }
byte_t m_bNoHdr
do [not] include field header in byte stream
static int nmPackFlatStream(const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a Flat message.
byte_t m_bTrace
do [not] trace packing/unpacking
uint_t m_eMsgId
message id (globally unique)
Definition: netmsgs.h:407
size_t m_uCount
number of message fields
Definition: netmsgs.h:408
#define NMCTL_INIT_DECL
Default Internal control declartion list.
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
void nmPrintBuf(FILE *fp, const char *sPreface, byte_t buf[], size_t uCount, size_t uNLFreq, uint_t uCol)
Pretty print buffer to opened file stream.
Definition: nmLibUtils.c:138
Internal Control Structure.
INLINE_IN_H int nmPackInt ( int  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an signed int integer into the message buffer.

Alias for nmPackS32().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 621 of file netmsgs.h.

References nmPackU32().

623 {
624  return nmPackU32((uint_t)val, buf, bufSize, eEndian);
625 }
int nmPackU32(uint_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 32-bit integer into the message buffer.
Definition: nmLibPack.c:791
int nmPackITVMsg ( const NMMsgDef_T pMsgDef,
void *  pStruct,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an ITV message.

Parameters
pMsgDefPointer to message definition.
[in]pStructPointer to the associated, populated message structure.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 2254 of file nmLibPackITV.c.

References _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_sMsgName, _nm_msg_def_struct::m_uCount, NM_ECODE_NOMEM, NMCTL_INIT_DECL, NMITV_MSGHDR_SIZE, NMLIB_RAISE_ERROR, nmPackITVStream(), and nmPackU16().

Referenced by nmUnpackPointer().

2259 {
2260  NMCtl_T ctl = NMCTL_INIT_DECL;
2261  int n; // byte count/error code
2262  int k; // subbyte count/error code
2263 
2264  // too small
2265  if( bufSize < NMITV_MSGHDR_SIZE )
2266  {
2267  NMLIB_RAISE_ERROR(NM_ECODE_NOMEM, "%s(%u): msg_len=%u, hdr_size=%u",
2268  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, bufSize, NMITV_MSGHDR_SIZE);
2269  }
2270 
2271  // pack message id
2272  if( (n = nmPackU16((ushort)(pMsgDef->m_eMsgId), buf, bufSize, eEndian)) < 0 )
2273  {
2274  return n;
2275  }
2276 
2277  // pack field count
2278  buf[n++] = (byte_t)pMsgDef->m_uCount;
2279 
2280  // pack stream
2281  k = nmPackITVStream(pMsgDef, pStruct, &buf[n], bufSize-(size_t)n, eEndian,
2282  &ctl);
2283 
2284  return k >= 0? n+k: k;
2285 }
uint_t m_eMsgId
message id (globally unique)
Definition: netmsgs.h:407
size_t m_uCount
number of message fields
Definition: netmsgs.h:408
#define NMLIB_RAISE_ERROR(ecode, fmt,...)
Raise libnetmsgs error (i.e. return from calling function).
#define NMCTL_INIT_DECL
Default Internal control declartion list.
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
int nmPackU16(ushort_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 16-bit integer into the message buffer.
Definition: nmLibPack.c:762
static int nmPackITVStream(const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a ITV message.
#define NMITV_MSGHDR_SIZE
Definition: netmsgs.h:222
Internal Control Structure.
int nmPackITVMsgDebug ( const NMMsgDef_T pMsgDef,
void *  pStruct,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an ITV message, tracing message packing to stderr.

Parameters
pMsgDefPointer to message definition.
[in]pStructPointer to the associated, populated message structure.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 2299 of file nmLibPackITV.c.

References NMCtl_T::m_bTrace, _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_sMsgName, _nm_msg_def_struct::m_uCount, NM_ECODE_NOMEM, NMCTL_INIT_DECL, NMITV_MSGHDR_SIZE, NMLIB_RAISE_ERROR, nmPackITVStream(), nmPackU16(), and nmPrintBuf().

Referenced by nmUnpackPointer().

2304 {
2305  NMCtl_T ctl = NMCTL_INIT_DECL;
2306  int n; // byte count/error code
2307  int k; // subbyte count/error code
2308 
2309  ctl.m_bTrace = true;
2310 
2311  // too small
2312  if( bufSize < NMITV_MSGHDR_SIZE )
2313  {
2314  NMLIB_RAISE_ERROR(NM_ECODE_NOMEM, "%s(%u): msg_len=%u, hdr_size=%u",
2315  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, bufSize, NMITV_MSGHDR_SIZE);
2316  }
2317 
2318  // pack message id
2319  if( (n = nmPackU16((ushort)(pMsgDef->m_eMsgId), buf, bufSize, eEndian)) < 0 )
2320  {
2321  return n;
2322  }
2323 
2324  // pack field count
2325  buf[n++] = (byte_t)pMsgDef->m_uCount;
2326 
2327  // trace
2328  fprintf(stderr, "\n--- Packing ITV Message %s(%u): field_count=%zu\n",
2329  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, pMsgDef->m_uCount);
2330 
2331  // pack stream
2332  k = nmPackITVStream(pMsgDef, pStruct, &buf[n], bufSize-(size_t)n, eEndian,
2333  &ctl);
2334 
2335  if( k < 0 )
2336  {
2337  return k;
2338  }
2339 
2340  n += k;
2341 
2342  // trace final buffer
2343  fprintf(stderr, "Output Buffer (%zu bytes):\n", (size_t)n);
2344  nmPrintBuf(stderr, NULL, buf, (size_t)n, 16, 0);
2345  fprintf(stderr, "\n");
2346 
2347  return n;
2348 }
byte_t m_bTrace
do [not] trace packing/unpacking
uint_t m_eMsgId
message id (globally unique)
Definition: netmsgs.h:407
size_t m_uCount
number of message fields
Definition: netmsgs.h:408
#define NMLIB_RAISE_ERROR(ecode, fmt,...)
Raise libnetmsgs error (i.e. return from calling function).
#define NMCTL_INIT_DECL
Default Internal control declartion list.
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
int nmPackU16(ushort_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 16-bit integer into the message buffer.
Definition: nmLibPack.c:762
static int nmPackITVStream(const NMMsgDef_T *pMsgDef, void *pStruct, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a ITV message.
#define NMITV_MSGHDR_SIZE
Definition: netmsgs.h:222
void nmPrintBuf(FILE *fp, const char *sPreface, byte_t buf[], size_t uCount, size_t uNLFreq, uint_t uCol)
Pretty print buffer to opened file stream.
Definition: nmLibUtils.c:138
Internal Control Structure.
INLINE_IN_H int nmPackLong ( long  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an signed long integer into the message buffer.

Alias for nmPackS32() or nmPackS64() depending on sizeof(long).

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 651 of file netmsgs.h.

References nmPackS32(), and nmPackS64().

653 {
654  return sizeof(long) == 4?
655  nmPackS32((int)val, buf, bufSize, eEndian):
656  nmPackS64((long long)val, buf, bufSize, eEndian);
657 }
int nmPackS64(long long val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an signed 64-bit integer into the message buffer.
Definition: nmLibPack.c:885
INLINE_IN_H int nmPackS32(int val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack a signed 32-bit integer into the message buffer.
Definition: netmsgs.h:512
INLINE_IN_H int nmPackLongLong ( long long  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an signed long long integer into the message buffer.

Alias for nmPackS64().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 681 of file netmsgs.h.

References nmPackS64().

683 {
684  return nmPackS64((long long)val, buf, bufSize, eEndian);
685 }
int nmPackS64(long long val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an signed 64-bit integer into the message buffer.
Definition: nmLibPack.c:885
int nmPackP32 ( void *  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a 32-bit pointer into the message buffer.

If the machine architecture has 64-bit pointers, then only the LSB 4 bytes are packed.

Note
Pointer is always packed in native byte order.
Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1113 of file nmLibPack.c.

References _NM_CHK_MEM, NMFVAL_LEN_P32, NMFVAL_LEN_P64, NMLIB_WARNING, and PACKNATIVE.

Referenced by nmPackFlatP32(), nmPackITVP32(), and nmPackPointer().

1114 {
1115  static size_t fvalLen = NMFVAL_LEN_P32; // message field value length
1116  ulong_t luVal;
1117  uint_t uVal;
1118 
1119  _NM_CHK_MEM(bufSize, fvalLen);
1120 
1121  // long's are same size as void *'s. exceptions?
1122  luVal = *((ulong_t *)val);
1123 
1124  // 4-byte natvie pointer
1125  if( sizeof(void *) == fvalLen )
1126  {
1127  PACKNATIVE(luVal, buf);
1128  }
1129 
1130  // 8-byte native pointer - "convert"
1131  if( sizeof(void *) == NMFVAL_LEN_P64 )
1132  {
1133 #if HOST_WORD_SIZE == 64
1134  //if( luVal & 0xffffffff00000000 )
1135  if( (luVal) & 0xffffffff00000000 )
1136  {
1137  NMLIB_WARNING("%p: Packing 64-bit pointer in 32 bits lost non-zero "
1138  "significance.", (void *)luVal);
1139  }
1140 #endif // HOST_WORD_SIZE
1141  uVal = (uint_t)(luVal & 0xffffffff);
1142  PACKNATIVE(uVal, buf);
1143  }
1144 
1145 
1146  return (int)fvalLen;
1147 }
#define NMLIB_WARNING(fmt,...)
Log libnetmsgs warning.
Definition: nmLibInternal.h:80
#define PACKNATIVE(val, buf)
Pack an element into the message buffer in native byte order.
Definition: nmLibPack.c:216
#define NMFVAL_LEN_P32
32-bit pointer field value length
Definition: netmsgs.h:183
#define NMFVAL_LEN_P64
64-bit pointer field value length
Definition: netmsgs.h:184
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmPackP64 ( void *  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a 64-bit pointer into the message buffer.

If the machine architecture only supports 32-bit pointers, then the 4 MSBs are padded with 0's.

Note
Pointer is always packed in native byte order.
Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1160 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, NMFVAL_LEN_P32, NMFVAL_LEN_P64, and PACK64NATIVE.

Referenced by nmPackFlatP64(), nmPackITVP64(), and nmPackPointer().

1161 {
1162  static size_t fvalLen = NMFVAL_LEN_P64; // message field value length
1163 
1164  ulong_t luVal;
1165  uint_t uMSB; // Most Signifcant Bytes
1166  uint_t uLSB; // Least Signifcant Bytes
1167 
1168  _NM_CHK_MEM(bufSize, fvalLen);
1169 
1170  // long's are same size as void *'s. exceptions?
1171  luVal = *((ulong_t *)val);
1172 
1173  // 8-byte pointer
1174  if( sizeof(void *) == fvalLen )
1175  {
1176 #if HOST_WORD_SIZE == 64
1177  uMSB = (uint_t)(luVal >> 32);
1178  uLSB = (uint_t)(luVal & 0xffffffff);
1179 #else
1180  uMSB = 0;
1181  uLSB = (uint_t)luVal;
1182 #endif // HOST_WORD_SIZE
1183  }
1184 
1185  // 4-byte pointer
1186  else
1187  {
1188  _NM_CHK_ARCH(val, (size_t)NMFVAL_LEN_P32);
1189 
1190  uMSB = 0;
1191  uLSB = (uint_t)luVal;
1192  }
1193 
1194  PACK64NATIVE(uMSB, uLSB, buf);
1195 
1196  return (int)fvalLen;
1197 }
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
#define NMFVAL_LEN_P32
32-bit pointer field value length
Definition: netmsgs.h:183
#define PACK64NATIVE(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in native byte order.
Definition: nmLibPack.c:238
#define NMFVAL_LEN_P64
64-bit pointer field value length
Definition: netmsgs.h:184
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
INLINE_IN_H int nmPackPointer ( void *  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a (overloaded) void* pointer into the message buffer.

Alias for nmPackP32() or nmPackP64() depending on sizeof(void*).

Note
Pointer is always packed in native byte order.
Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 697 of file netmsgs.h.

References nmPackP32(), nmPackP64(), nmUnpackBuf(), nmUnpackF32(), nmUnpackF64(), nmUnpackP32(), nmUnpackP64(), nmUnpackS64(), nmUnpackU16(), nmUnpackU32(), nmUnpackU64(), and nmUnpackU8().

699 {
700  return sizeof(void*) == 4?
701  nmPackP32(val, buf, bufSize, eEndian):
702  nmPackP64(val, buf, bufSize, eEndian);
703 }
int nmPackP64(void *val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack a 64-bit pointer into the message buffer.
Definition: nmLibPack.c:1160
int nmPackP32(void *val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack a 32-bit pointer into the message buffer.
Definition: nmLibPack.c:1113
INLINE_IN_H int nmPackS16 ( short  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a signed 16-bit integer into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 500 of file netmsgs.h.

References nmPackU16().

Referenced by nmPackFlatS16(), and nmPackITVS16().

502 {
503  return nmPackU16((ushort_t)val, buf, bufSize, eEndian);
504 }
int nmPackU16(ushort_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 16-bit integer into the message buffer.
Definition: nmLibPack.c:762
INLINE_IN_H int nmPackS32 ( int  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a signed 32-bit integer into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 512 of file netmsgs.h.

References nmPackU32().

Referenced by nmPackFlatS32(), nmPackITVS32(), and nmPackLong().

514 {
515  return nmPackU32((uint_t)val, buf, bufSize, eEndian);
516 }
int nmPackU32(uint_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 32-bit integer into the message buffer.
Definition: nmLibPack.c:791
int nmPackS64 ( long long  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an signed 64-bit integer into the message buffer.

If the machine architecture only supports 32-bit long longs, then the 4 MSBs are signed extended.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 885 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_S32, NMFVAL_LEN_S64, PACK64BIG, PACK64LITTLE, PACK64NATIVE, PACKBIG, PACKLITTLE, and PACKNATIVE.

Referenced by nmPackFlatS64(), nmPackITVS64(), nmPackLong(), and nmPackLongLong().

886 {
887  static size_t fvalLen = NMFVAL_LEN_S64; // message field value length
888 
889  uint_t uMSB; // most significant bytes
890  uint_t uLSB; // least signifcant bytes
891 
892  _NM_CHK_MEM(bufSize, fvalLen);
893 
894  // 8-byte signed long long
895  if( sizeof(long long) == fvalLen )
896  {
897  switch( eEndian )
898  {
899  case NMEndianLittle:
900  PACKLITTLE(val, buf);
901  break;
902  case NMEndianNative:
903  PACKNATIVE(val, buf);
904  break;
905  case NMEndianBig:
906  default:
907  PACKBIG(val, buf);
908  break;
909  }
910  }
911 
912  // 4-byte signed long long
913  else
914  {
915  _NM_CHK_ARCH(val, (size_t)NMFVAL_LEN_S32);
916 
917  uMSB = val & 0x80000000? 0xffffffff: 0x00000000; // extend sign
918  uLSB = (uint_t)val;
919 
920  switch( eEndian )
921  {
922  case NMEndianLittle:
923  PACK64LITTLE(uMSB, uLSB, buf);
924  break;
925  case NMEndianNative:
926  PACK64NATIVE(uMSB, uLSB, buf);
927  break;
928  case NMEndianBig:
929  default:
930  PACK64BIG(uMSB, uLSB, buf);
931  break;
932  }
933  }
934 
935  return (int)fvalLen;
936 }
#define NMFVAL_LEN_S32
signed 32-bit field value length
Definition: netmsgs.h:178
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
Most Significant Byte first.
Definition: netmsgs.h:102
#define PACK64BIG(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in big-endian byte order.
Definition: nmLibPack.c:436
native processor order
Definition: netmsgs.h:104
#define PACKBIG(val, buf)
Pack an element into the message buffer in big-endian byte order.
Definition: nmLibPack.c:397
#define PACKLITTLE(val, buf)
Pack an element into the message buffer in little-endian byte order.
Definition: nmLibPack.c:413
#define PACKNATIVE(val, buf)
Pack an element into the message buffer in native byte order.
Definition: nmLibPack.c:216
#define PACK64LITTLE(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in little-endian byte order.
Definition: nmLibPack.c:477
#define PACK64NATIVE(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in native byte order.
Definition: nmLibPack.c:238
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
#define NMFVAL_LEN_S64
signed 64-bit field value length
Definition: netmsgs.h:180
INLINE_IN_H int nmPackS8 ( signed char  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a signed 8-bit byte into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 488 of file netmsgs.h.

References nmPackU8().

Referenced by nmPackFlatS8(), and nmPackITVS8().

490 {
491  return nmPackU8((byte_t)val, buf, bufSize, eEndian);
492 }
int nmPackU8(byte_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 8-bit byte into the message buffer.
Definition: nmLibPack.c:745
INLINE_IN_H int nmPackSChar ( signed char  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack a signed char integer value into the message buffer.

Alias for nmPackS8().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 540 of file netmsgs.h.

References nmPackU8().

542 {
543  return nmPackU8((byte_t)val, buf, bufSize, eEndian);
544 }
int nmPackU8(byte_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 8-bit byte into the message buffer.
Definition: nmLibPack.c:745
INLINE_IN_H int nmPackShort ( short  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an signed short integer into the message buffer.

Alias for nmPackS16().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 593 of file netmsgs.h.

References nmPackU16().

595 {
596  return nmPackU16((ushort_t)val, buf, bufSize, eEndian);
597 }
int nmPackU16(ushort_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 16-bit integer into the message buffer.
Definition: nmLibPack.c:762
int nmPackU16 ( ushort_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned 16-bit integer into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 762 of file nmLibPack.c.

References _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_U16, PACKBIG, PACKLITTLE, and PACKNATIVE.

Referenced by nmPackFlatU16(), nmPackITVMsg(), nmPackITVMsgDebug(), nmPackITVU16(), nmPackS16(), nmPackShort(), and nmPackUShort().

763 {
764  static size_t fvalLen = NMFVAL_LEN_U16; // message field value length
765 
766  _NM_CHK_MEM(bufSize, fvalLen);
767 
768  switch( eEndian )
769  {
770  case NMEndianLittle:
771  PACKLITTLE(val, buf);
772  break;
773  case NMEndianNative:
774  PACKNATIVE(val, buf);
775  break;
776  case NMEndianBig:
777  default:
778  PACKBIG(val, buf);
779  break;
780  }
781 
782  return (int)fvalLen;
783 }
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define PACKBIG(val, buf)
Pack an element into the message buffer in big-endian byte order.
Definition: nmLibPack.c:397
#define PACKLITTLE(val, buf)
Pack an element into the message buffer in little-endian byte order.
Definition: nmLibPack.c:413
#define PACKNATIVE(val, buf)
Pack an element into the message buffer in native byte order.
Definition: nmLibPack.c:216
#define NMFVAL_LEN_U16
unsigned 16-bit field value length
Definition: netmsgs.h:175
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmPackU32 ( uint_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned 32-bit integer into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 791 of file nmLibPack.c.

References _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_U32, PACKBIG, PACKLITTLE, and PACKNATIVE.

Referenced by nmPackFlatU32(), nmPackInt(), nmPackITVU32(), nmPackS32(), nmPackUInt(), and nmPackULong().

792 {
793  static size_t fvalLen = NMFVAL_LEN_U32; // message field value length
794 
795  _NM_CHK_MEM(bufSize, fvalLen);
796 
797  switch( eEndian )
798  {
799  case NMEndianLittle:
800  PACKLITTLE(val, buf);
801  break;
802  case NMEndianNative:
803  PACKNATIVE(val, buf);
804  break;
805  case NMEndianBig:
806  default:
807  PACKBIG(val, buf);
808  break;
809  }
810 
811  return (int)fvalLen;
812 }
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define PACKBIG(val, buf)
Pack an element into the message buffer in big-endian byte order.
Definition: nmLibPack.c:397
#define PACKLITTLE(val, buf)
Pack an element into the message buffer in little-endian byte order.
Definition: nmLibPack.c:413
#define PACKNATIVE(val, buf)
Pack an element into the message buffer in native byte order.
Definition: nmLibPack.c:216
#define NMFVAL_LEN_U32
unsigned 32-bit field value length
Definition: netmsgs.h:177
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmPackU64 ( ulonglong_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned 64-bit integer into the message buffer.

If the machine architecture only supports 32-bit long longs, then the 4 MSBs are padded with zero's.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 823 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_U32, NMFVAL_LEN_U64, PACK64BIG, PACK64LITTLE, PACK64NATIVE, PACKBIG, PACKLITTLE, and PACKNATIVE.

Referenced by nmPackFlatU64(), nmPackITVU64(), nmPackULong(), and nmPackULongLong().

824 {
825  static size_t fvalLen = NMFVAL_LEN_U64; // message field value length
826 
827  uint_t uMSB; // most significant bytes
828  uint_t uLSB; // least signifcant bytes
829 
830  _NM_CHK_MEM(bufSize, fvalLen);
831 
832  // 8-byte unsigned long long
833  if( sizeof(ulonglong_t) == fvalLen )
834  {
835  switch( eEndian )
836  {
837  case NMEndianLittle:
838  PACKLITTLE(val, buf);
839  break;
840  case NMEndianNative:
841  PACKNATIVE(val, buf);
842  break;
843  case NMEndianBig:
844  default:
845  PACKBIG(val, buf);
846  break;
847  }
848  }
849 
850  // 4-byte unsigned long long
851  else
852  {
853  _NM_CHK_ARCH(val, (size_t)NMFVAL_LEN_U32);
854 
855  uMSB = 0;
856  uLSB = (uint_t)val;
857 
858  switch( eEndian )
859  {
860  case NMEndianLittle:
861  PACK64LITTLE(uMSB, uLSB, buf);
862  break;
863  case NMEndianNative:
864  PACK64NATIVE(uMSB, uLSB, buf);
865  break;
866  case NMEndianBig:
867  default:
868  PACK64BIG(uMSB, uLSB, buf);
869  break;
870  }
871  }
872 
873  return (int)fvalLen;
874 }
#define NMFVAL_LEN_U64
unsigned 64-bit field value length
Definition: netmsgs.h:179
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
Most Significant Byte first.
Definition: netmsgs.h:102
#define PACK64BIG(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in big-endian byte order.
Definition: nmLibPack.c:436
native processor order
Definition: netmsgs.h:104
#define PACKBIG(val, buf)
Pack an element into the message buffer in big-endian byte order.
Definition: nmLibPack.c:397
#define PACKLITTLE(val, buf)
Pack an element into the message buffer in little-endian byte order.
Definition: nmLibPack.c:413
#define PACKNATIVE(val, buf)
Pack an element into the message buffer in native byte order.
Definition: nmLibPack.c:216
#define PACK64LITTLE(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in little-endian byte order.
Definition: nmLibPack.c:477
#define PACK64NATIVE(uMSB, uLSB, buf)
Pack two 4-btye unsigned integers into the message buffer in native byte order.
Definition: nmLibPack.c:238
#define NMFVAL_LEN_U32
unsigned 32-bit field value length
Definition: netmsgs.h:177
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmPackU8 ( byte_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned 8-bit byte into the message buffer.

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 745 of file nmLibPack.c.

References _NM_CHK_MEM, and NMFVAL_LEN_U8.

Referenced by nmPackBool(), nmPackByte(), nmPackChar(), nmPackFlatU8(), nmPackITVU8(), nmPackS8(), and nmPackSChar().

746 {
747  static size_t fvalLen = NMFVAL_LEN_U8; // message field value length
748 
749  _NM_CHK_MEM(bufSize, fvalLen);
750 
751  buf[0] = val & 0xff;
752 
753  return (int)fvalLen;
754 }
#define NMFVAL_LEN_U8
unsigned 8-bit field value length
Definition: netmsgs.h:172
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
INLINE_IN_H int nmPackUInt ( uint_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned int integer into the message buffer.

Alias for nmPackU32().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 607 of file netmsgs.h.

References nmPackU32().

609 {
610  return nmPackU32((uint_t)val, buf, bufSize, eEndian);
611 }
int nmPackU32(uint_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 32-bit integer into the message buffer.
Definition: nmLibPack.c:791
INLINE_IN_H int nmPackULong ( ulong_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned long integer into the message buffer.

Alias for nmPackU32() or nmPackU64() depending on sizeof(ulong_t).

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 635 of file netmsgs.h.

References nmPackU32(), and nmPackU64().

637 {
638  return sizeof(ulong_t) == 4?
639  nmPackU32((uint_t)val, buf, bufSize, eEndian):
640  nmPackU64((ulonglong_t)val, buf, bufSize, eEndian);
641 }
int nmPackU32(uint_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 32-bit integer into the message buffer.
Definition: nmLibPack.c:791
int nmPackU64(ulonglong_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 64-bit integer into the message buffer.
Definition: nmLibPack.c:823
INLINE_IN_H int nmPackULongLong ( ulonglong_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned long long integer into the message buffer.

Alias for nmPackU64().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 667 of file netmsgs.h.

References nmPackU64().

669 {
670  return nmPackU64((ulonglong_t)val, buf, bufSize, eEndian);
671 }
int nmPackU64(ulonglong_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 64-bit integer into the message buffer.
Definition: nmLibPack.c:823
INLINE_IN_H int nmPackUShort ( ushort_t  val,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian 
)

Pack an unsigned short integer into the message buffer.

Alias for nmPackU16().

Parameters
[in]valValue to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 579 of file netmsgs.h.

References nmPackU16().

581 {
582  return nmPackU16((ushort_t)val, buf, bufSize, eEndian);
583 }
int nmPackU16(ushort_t val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack an unsigned 16-bit integer into the message buffer.
Definition: nmLibPack.c:762
void nmPrintBits ( FILE *  fp,
const char *  sPreface,
ulonglong_t  uVal,
uint_t  uMsb,
uint_t  uCnt 
)

Pretty print bits in value.

Parameters
fpFile pointer.
sPrefaceOptional bit preface string (set to NULL for no preface).
uValBits to print.
uMsbStarting most significant bit.
uCntNumber of bits.

Definition at line 174 of file nmLibUtils.c.

179 {
180  uint_t i;
181 
182  if( sPreface && *sPreface )
183  {
184  fprintf(fp, "%s:", sPreface);
185  }
186 
187  for(i=0; i<uCnt; ++i)
188  {
189  if( (uMsb % 8) == 7 )
190  {
191  if( i != 0 )
192  {
193  printf(" ");
194  }
195  }
196  (uVal >> uMsb) & 0x01? printf("1"): printf("0");
197  --uMsb;
198  }
199 }
void nmPrintBuf ( FILE *  fp,
const char *  sPreface,
byte_t  buf[],
size_t  uCount,
size_t  uNLFreq,
uint_t  uCol 
)

Pretty print buffer to opened file stream.

Parameters
fpFile pointer.
sPrefaceOptional buffer preface string (set to NULL for no preface).
bufBuffer to print.
uCountNumber of bytes to print.
uNLFreqNewline frequency (set to 0 for no newlines).
uColColumn alignment number.

Definition at line 138 of file nmLibUtils.c.

Referenced by nmPackFlatMsgDebug(), nmPackITVMsgDebug(), nmTraceField(), nmUnpackFlatMsgDebug(), and nmUnpackITVMsgDebug().

144 {
145  size_t i;
146 
147  if( sPreface && *sPreface )
148  {
149  fprintf(fp, "%s:", sPreface);
150  }
151 
152  for(i=0; i<uCount; ++i)
153  {
154  if( (uNLFreq > 0) && ((i % uNLFreq) == 0) )
155  {
156  if( i != 0 )
157  {
158  fprintf(fp, "\n%*s", uCol, "");
159  }
160  }
161  fprintf(fp, " 0x%02x", buf[i]);
162  }
163 }
const char* nmStrError ( int  ecode)

Get the error string describing the BotSense error code.

The absolute value of the error code is taken prior retrieving the string. An unknown or out-of-range error code will be mapped to NM_ECODE_BADEC.

Parameters
ecodeBotSense error code.
Returns
Returns the appropriate error code string.

Definition at line 114 of file nmLibUtils.c.

References NM_ECODE_BADEC, and nmEcodeStrTbl.

115 {
116  if( ecode < 0 )
117  {
118  ecode = -ecode;
119  }
120 
121  if( ecode >= arraysize(nmEcodeStrTbl) )
122  {
123  ecode = NM_ECODE_BADEC;
124  }
125  return nmEcodeStrTbl[ecode];
126 }
#define NM_ECODE_BADEC
internal inconsistency or bug
Definition: netmsgs.h:81
static const char * nmEcodeStrTbl[]
NetMsgs Error Code String Table.
Definition: nmLibUtils.c:69
INLINE_IN_H int nmUnpackBool ( byte_t  buf[],
size_t  bufSize,
bool_t *  pVal,
NMEndian_T  eEndian 
)

Unpack a boolean value from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 823 of file netmsgs.h.

References nmUnpackU8().

Referenced by nmUnpackFlatBool(), and nmUnpackITVBool().

825 {
826  *pVal = 0; // clear all sizeof(int) bits
827  return nmUnpackU8(buf, bufSize, (byte_t *)pVal, eEndian);
828 }
int nmUnpackU8(byte_t buf[], size_t bufSize, byte_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 8-bit byte from the message buffer.
Definition: nmLibPack.c:1239
int nmUnpackBuf ( byte_t  buf[],
size_t  bufSize,
byte_t  bufDst[],
size_t  uCount,
NMEndian_T  eEndian 
)

Unpack a byte buffer from the message buffer.

The source and message buffer memory areas can overlap.

Note
The buffer is always packed in sequential order ignoring the byte order parameter.
Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]bufDstDestination output buffer.
uCountNumber of bytes to copy.
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1735 of file nmLibPack.c.

References _NM_CHK_MEM.

Referenced by nmPackPointer().

1740 {
1741  _NM_CHK_MEM(bufSize, uCount);
1742 
1743  // safe copy
1744  memmove(bufDst, buf, uCount);
1745 
1746  return (int)uCount;
1747 }
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
INLINE_IN_H int nmUnpackByte ( byte_t  buf[],
size_t  bufSize,
byte_t *  pVal,
NMEndian_T  eEndian 
)

Unpack one byte from the message buffer.

Alias for nmUnpackU8().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 785 of file netmsgs.h.

References nmUnpackU8().

787 {
788  return nmUnpackU8(buf, bufSize, (byte_t *)pVal, eEndian);
789 }
int nmUnpackU8(byte_t buf[], size_t bufSize, byte_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 8-bit byte from the message buffer.
Definition: nmLibPack.c:1239
INLINE_IN_H int nmUnpackChar ( byte_t  buf[],
size_t  bufSize,
char *  pVal,
NMEndian_T  eEndian 
)

Unpack an 8-bit ASCII character from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 811 of file netmsgs.h.

References nmUnpackU8().

813 {
814  return nmUnpackU8(buf, bufSize, (byte_t *)pVal, eEndian);
815 }
int nmUnpackU8(byte_t buf[], size_t bufSize, byte_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 8-bit byte from the message buffer.
Definition: nmLibPack.c:1239
int nmUnpackF32 ( byte_t  buf[],
size_t  bufSize,
float *  pVal,
NMEndian_T  eEndian 
)

Unpack a 32-bit float from the message buffer.

The IEEE 754 32-bit format is used with both the big and little endian byte orders.

Note
On some machines, while integers were represented in little-endian form, floating point numbers were represented in big-endian form. Because there are many floating point formats, and a lack of a standard network representation, no standard for transferring floating point values has been made - Wikipedia.
Todo:
Detect non-IEEE 754 formats and convert to IEEE 754 prior to packing.
Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1472 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_F32, UNPACKBIG, UNPACKLITTLE, and UNPACKNATIVE.

Referenced by nmPackPointer(), nmUnpackFlatF32(), and nmUnpackITVF32().

1473 {
1474  static size_t fvalLen = NMFVAL_LEN_F32; // message field value length
1475 
1476  _NM_CHK_MEM(bufSize, fvalLen);
1477  _NM_CHK_ARCH(*pVal, fvalLen);
1478 
1479  switch( eEndian )
1480  {
1481  case NMEndianLittle:
1482  UNPACKLITTLE(buf, pVal);
1483  break;
1484  case NMEndianNative:
1485  UNPACKNATIVE(buf, pVal);
1486  break;
1487  case NMEndianBig:
1488  default:
1489  UNPACKBIG(buf, pVal);
1490  break;
1491  }
1492 
1493 
1494  return (int)fvalLen;
1495 }
#define UNPACKNATIVE(buf, pval)
Unpack an element from the message buffer in native byte order.
Definition: nmLibPack.c:226
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define NMFVAL_LEN_F32
32-bit floating-point number field val len
Definition: netmsgs.h:181
#define UNPACKBIG(buf, pval)
Unpack an element from the message buffer in big-endian byte order.
Definition: nmLibPack.c:405
#define UNPACKLITTLE(buf, pval)
Unpack an element from the message buffer in little-endian byte order.
Definition: nmLibPack.c:421
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmUnpackF64 ( byte_t  buf[],
size_t  bufSize,
double *  pVal,
NMEndian_T  eEndian 
)

Unpack a 64-bit float from the message buffer.

The IEEE 754 64-bit format is used with both the big and little endian byte orders. If the machine architecture only supports 32-bit doubles, then mantissa truncation will occur.

Note
On some machines, while integers were represented in little-endian form, floating point numbers were represented in big-endian form. Because there are many floating point formats, and a lack of a standard network representation, no standard for transferring floating point values has been made - Wikipedia.
Todo:
Detect non-IEEE 754 formats and convert to IEEE 754 prior to packing.
Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1517 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, IEEE754_F32_EXP_MAX, IEEE754_F32_EXP_MIN, IEEE754_F32_F64_MANTISSA0_SHIFT, IEEE754_F32_F64_MANTISSA1_MASK, IEEE754_F32_F64_MANTISSA1_SHIFT, IEEE754_F32_Inf, IEEE754_F32_MANTISSA_MASK, IEEE754_F32_NaN, IEEE754_F32_Zero, IEEE754_F64_EXPONENT_MASK, IEEE754_F64_EXPONENT_SHIFT, ieee754_f64_is_inf(), ieee754_f64_is_nan(), ieee754_f64_is_zero(), IEEE754_F64_MANTISSA0_MASK, IEEE754_F64_MANTISSA0_SHIFT, IEEE754_F64_MANTISSA1_MASK, IEEE754_F64_MANTISSA1_SHIFT, IEEE754_F64_SIGN_MASK, IEEE754_F64_SIGN_SHIFT, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_F32, NMFVAL_LEN_F64, NMLIB_WARNING, UNPACK64BIG, UNPACK64LITTLE, UNPACK64NATIVE, UNPACKBIG, UNPACKLITTLE, and UNPACKNATIVE.

Referenced by nmPackPointer(), nmUnpackFlatF64(), and nmUnpackITVF64().

1518 {
1519  static size_t fvalLen = NMFVAL_LEN_F64; // message field value length
1520 
1521  uint_t uMSB; // Most Signifcant Bytes
1522  uint_t uLSB; // Least Signifcant Bytes
1523  int exponent; // ieee754 unbiased exponent
1524  union ieee754_float f; // 4-byte floating-point number
1525  union ieee754_double d; // 8-byte floating-point number
1526 
1527  _NM_CHK_MEM(bufSize, fvalLen);
1528 
1529  // 8-byte doubles
1530  if( sizeof(double) == (size_t)NMFVAL_LEN_F64 )
1531  {
1532  switch( eEndian )
1533  {
1534  case NMEndianLittle:
1535  UNPACKLITTLE(buf, &d.d);
1536  break;
1537  case NMEndianNative:
1538  UNPACKNATIVE(buf, &d.d);
1539  break;
1540  case NMEndianBig:
1541  default:
1542  UNPACKBIG(buf, &d.d);
1543  break;
1544  }
1545 
1546  *pVal = d.d;
1547  }
1548 
1549  else // 4-byte doubles
1550  {
1551  _NM_CHK_ARCH(*pVal, (size_t)NMFVAL_LEN_F32);
1552 
1553  switch( eEndian )
1554  {
1555  case NMEndianLittle:
1556  UNPACK64LITTLE(buf, &uMSB, &uLSB);
1557  break;
1558  case NMEndianNative:
1559  UNPACK64NATIVE(buf, &uMSB, &uLSB);
1560  break;
1561  case NMEndianBig:
1562  default:
1563  UNPACK64BIG(buf, &uMSB, &uLSB);
1564  break;
1565  }
1566 
1567  d.ieee.negative = ((uMSB >> IEEE754_F64_SIGN_SHIFT)
1568  & IEEE754_F64_SIGN_MASK)? 1: 0;
1569  d.ieee.exponent = (uMSB >> IEEE754_F64_EXPONENT_SHIFT)
1571  d.ieee.mantissa0 = (uMSB >> IEEE754_F64_MANTISSA0_SHIFT)
1573  d.ieee.mantissa1 = (uLSB >> IEEE754_F64_MANTISSA1_SHIFT)
1575 
1576  // unbias the exponent
1577  exponent = (int)d.ieee.exponent - IEEE754_DOUBLE_BIAS;
1578 
1579  // special Not-a-Number case
1580  if( ieee754_f64_is_nan(d) )
1581  {
1582  f = IEEE754_F32_NaN;
1583  }
1584 
1585  // special infinity cases
1586  else if( ieee754_f64_is_inf(d) )
1587  {
1588  f = IEEE754_F32_Inf;
1589  }
1590 
1591  // exponent overflow
1592  else if( exponent > IEEE754_F32_EXP_MAX )
1593  {
1594  f = IEEE754_F32_Inf;
1595  NMLIB_WARNING("floating-point number overflow.");
1596  }
1597 
1598  // exponent overflow
1599  else if( exponent < IEEE754_F32_EXP_MIN )
1600  {
1601  f = IEEE754_F32_Zero;
1602  NMLIB_WARNING("floating-point number underflow.");
1603  }
1604 
1605  // special zero cases
1606  else if( ieee754_f64_is_zero(d) )
1607  {
1608  f = IEEE754_F32_Zero;
1609  }
1610 
1611  // "normal" floating-point numbers
1612  else
1613  {
1614  f.ieee.exponent = (byte_t)(exponent + IEEE754_FLOAT_BIAS);
1615  f.ieee.mantissa = ( (uint_t)((d.ieee.mantissa0
1618  | (uint_t)((d.ieee.mantissa1
1622  if( (d.ieee.mantissa1 & (uint_t)~IEEE754_F32_F64_MANTISSA1_MASK) != 0 )
1623  {
1624  NMLIB_WARNING("floating-point number mantissa truncation.");
1625  }
1626  }
1627 
1628  // preserve the sign
1629  f.ieee.negative = d.ieee.negative;
1630 
1631  *pVal = (double)f.f;
1632  }
1633 
1634  return (int)fvalLen;
1635 }
#define UNPACKNATIVE(buf, pval)
Unpack an element from the message buffer in native byte order.
Definition: nmLibPack.c:226
#define IEEE754_F32_F64_MANTISSA1_SHIFT
lsb mantissa shift
Definition: nmLibPack.c:544
#define IEEE754_F64_MANTISSA0_SHIFT
f64 msb mantissa shift
Definition: nmLibPack.c:535
#define IEEE754_F64_SIGN_SHIFT
f64 sign shift
Definition: nmLibPack.c:531
#define IEEE754_F32_EXP_MAX
maximum power of 2 exponent
Definition: nmLibPack.c:550
#define IEEE754_F64_MANTISSA1_MASK
f64 lsb mantissa mask
Definition: nmLibPack.c:538
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
Most Significant Byte first.
Definition: netmsgs.h:102
#define NMFVAL_LEN_F64
64-bit floating-point number field val len
Definition: netmsgs.h:182
#define IEEE754_F64_MANTISSA0_MASK
f64 msb mantissa mask
Definition: nmLibPack.c:536
native processor order
Definition: netmsgs.h:104
#define UNPACK64NATIVE(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in native byte order. ...
Definition: nmLibPack.c:250
#define IEEE754_F64_EXPONENT_MASK
f64 exponent mask
Definition: nmLibPack.c:534
#define NMLIB_WARNING(fmt,...)
Log libnetmsgs warning.
Definition: nmLibInternal.h:80
#define NMFVAL_LEN_F32
32-bit floating-point number field val len
Definition: netmsgs.h:181
#define IEEE754_F64_EXPONENT_SHIFT
f64 exponent shift
Definition: nmLibPack.c:533
static bool_t ieee754_f64_is_inf(union ieee754_double d)
Test if 64-bit floating-point number is &plusmn; infinity.
Definition: nmLibPack.c:664
static const union ieee754_float IEEE754_F32_NaN
Definition: nmLibPack.c:566
#define IEEE754_F32_F64_MANTISSA1_MASK
lsb mantissa mask
Definition: nmLibPack.c:545
#define UNPACK64BIG(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in big-endian byte order.
Definition: nmLibPack.c:457
#define UNPACK64LITTLE(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in little-endian byte order...
Definition: nmLibPack.c:498
#define UNPACKBIG(buf, pval)
Unpack an element from the message buffer in big-endian byte order.
Definition: nmLibPack.c:405
#define IEEE754_F32_MANTISSA_MASK
f32 mantissa mask
Definition: nmLibPack.c:521
#define UNPACKLITTLE(buf, pval)
Unpack an element from the message buffer in little-endian byte order.
Definition: nmLibPack.c:421
Least Significant Byte first.
Definition: netmsgs.h:103
static bool_t ieee754_f64_is_zero(union ieee754_double d)
Test if 64-bit floating-point number is &plusmn; 0.0.
Definition: nmLibPack.c:686
#define IEEE754_F64_MANTISSA1_SHIFT
f64 lsb mantissa shift
Definition: nmLibPack.c:537
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
#define IEEE754_F64_SIGN_MASK
f64 sign mask
Definition: nmLibPack.c:532
static const union ieee754_float IEEE754_F32_Inf
Definition: nmLibPack.c:587
static bool_t ieee754_f64_is_nan(union ieee754_double d)
Test if 64-bit floating-point number is a NaN.
Definition: nmLibPack.c:642
static const union ieee754_float IEEE754_F32_Zero
Definition: nmLibPack.c:608
#define IEEE754_F32_F64_MANTISSA0_SHIFT
msb mantissa shift
Definition: nmLibPack.c:543
#define IEEE754_F32_EXP_MIN
minimum power of 2 exponent
Definition: nmLibPack.c:551
int nmUnpackFlatMsg ( const NMMsgDef_T pMsgDef,
byte_t  buf[],
size_t  uMsgLen,
void *  pStruct,
NMEndian_T  eEndian 
)

Unpack a Flat message.

Parameters
pMsgDefPointer to message definition.
[in]bufInput message buffer.
uMsgLenLength of message (bytes) in input buffer.
[out]pStructPointer to the associated message structure to populate.
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, returns < 0.

Definition at line 1490 of file nmLibPackFlat.c.

References NMCtl_T::m_bNoHdr, NMCTL_INIT_DECL, and nmUnpackFlatStream().

Referenced by nmUnpackPointer().

1495 {
1496  NMCtl_T ctl = NMCTL_INIT_DECL;
1497  int n; // byte count/error code
1498 
1499  ctl.m_bNoHdr = true;
1500 
1501  // unpack stream
1502  n = nmUnpackFlatStream(pMsgDef, buf, uMsgLen, pStruct, eEndian, &ctl);
1503 
1504  // return code
1505  return n;
1506 }
byte_t m_bNoHdr
do [not] include field header in byte stream
static int nmUnpackFlatStream(const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, void *pStruct, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an Flat byte stream.
#define NMCTL_INIT_DECL
Default Internal control declartion list.
Internal Control Structure.
int nmUnpackFlatMsgDebug ( const NMMsgDef_T pMsgDef,
byte_t  buf[],
size_t  uMsgLen,
void *  pStruct,
NMEndian_T  eEndian 
)

Unpack a Flat message, tracing unpacking to stderr.

Parameters
pMsgDefPointer to message definition.
[in]bufInput message buffer.
uMsgLenLength of message (bytes) in input buffer.
[out]pStructPointer to the associated message structure to populate.
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1520 of file nmLibPackFlat.c.

References NMCtl_T::m_bNoHdr, NMCtl_T::m_bTrace, _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_sMsgName, _nm_msg_def_struct::m_uCount, NMCTL_INIT_DECL, nmPrintBuf(), and nmUnpackFlatStream().

Referenced by nmUnpackPointer().

1525 {
1526  NMCtl_T ctl = NMCTL_INIT_DECL;
1527  int n; // byte count/error code
1528 
1529  ctl.m_bNoHdr = true;
1530  ctl.m_bTrace = true;
1531 
1532  // trace
1533  fprintf(stderr, "\n--- Unpacking Flat Message %s(%u): field_count=%zu\n",
1534  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, pMsgDef->m_uCount);
1535  fprintf(stderr, "Input Buffer (%zu bytes):\n", uMsgLen);
1536  nmPrintBuf(stderr, NULL, buf, uMsgLen, 16, 0);
1537  fprintf(stderr, "\n");
1538 
1539  // unpack stream
1540  n = nmUnpackFlatStream(pMsgDef, buf, uMsgLen, pStruct, eEndian, &ctl);
1541 
1542  // return code
1543  return n;
1544 }
byte_t m_bNoHdr
do [not] include field header in byte stream
byte_t m_bTrace
do [not] trace packing/unpacking
uint_t m_eMsgId
message id (globally unique)
Definition: netmsgs.h:407
size_t m_uCount
number of message fields
Definition: netmsgs.h:408
static int nmUnpackFlatStream(const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, void *pStruct, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an Flat byte stream.
#define NMCTL_INIT_DECL
Default Internal control declartion list.
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
void nmPrintBuf(FILE *fp, const char *sPreface, byte_t buf[], size_t uCount, size_t uNLFreq, uint_t uCol)
Pretty print buffer to opened file stream.
Definition: nmLibUtils.c:138
Internal Control Structure.
INLINE_IN_H int nmUnpackInt ( byte_t  buf[],
size_t  bufSize,
int *  pVal,
NMEndian_T  eEndian 
)

Unpack an signed int integer from the message buffer.

Alias for nmUnpackS32().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 880 of file netmsgs.h.

References nmUnpackU32().

882 {
883  return nmUnpackU32(buf, bufSize, (uint_t *)pVal, eEndian);
884 }
int nmUnpackU32(byte_t buf[], size_t bufSize, uint_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 32-bit integer from the message buffer.
Definition: nmLibPack.c:1288
int nmUnpackITVMsg ( const NMMsgDef_T pMsgDef,
byte_t  buf[],
size_t  uMsgLen,
void *  pStruct,
NMEndian_T  eEndian 
)

Unpack a ITV message.

Parameters
pMsgDefPointer to message definition.
[in]bufInput message buffer.
uMsgLenLength of message (bytes) in input buffer.
[out]pStructPointer to the associated message structure to populate.
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, returns < 0.

Definition at line 2364 of file nmLibPackITV.c.

References _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_sMsgName, NM_ECODE_MSGID, NM_ECODE_NOMEM, NMCTL_INIT_DECL, NMITV_MSGHDR_SIZE, NMLIB_RAISE_ERROR, nmUnpackITVStream(), and nmUnpackU16().

Referenced by nmUnpackPointer().

2369 {
2370  NMCtl_T ctl = NMCTL_INIT_DECL;
2371  ushort_t eMsgId; // message id in buffer
2372  size_t uCount; // field count in buffer
2373  int n; // byte count/error code
2374  int k; // subbyte count/error code
2375 
2376  // too small
2377  if( uMsgLen < NMITV_MSGHDR_SIZE )
2378  {
2379  NMLIB_RAISE_ERROR(NM_ECODE_NOMEM, "%s(%u): msg_len=%u, hdr_size=%u",
2380  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, uMsgLen, NMITV_MSGHDR_SIZE);
2381  }
2382 
2383  // unpack message id
2384  if( (n = nmUnpackU16(buf, uMsgLen, &eMsgId, eEndian)) < 0 )
2385  {
2386  return n;
2387  }
2388 
2389  // field count
2390  uCount = (size_t)buf[n++];
2391 
2392  // mismatch error
2393  if( (uint_t)(pMsgDef->m_eMsgId) != (uint_t)eMsgId )
2394  {
2395  NMLIB_RAISE_ERROR(NM_ECODE_MSGID, "%s(%u): rcv'd msgid=%u != msgdef's",
2396  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, eMsgId);
2397  }
2398 
2399  // unpack stream
2400  k = nmUnpackITVStream(pMsgDef, &buf[n], uMsgLen-(size_t)n, uCount,
2401  pStruct, eEndian, &ctl);
2402 
2403  // return code
2404  return k>=0? n+k: k;
2405 }
int nmUnpackU16(byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 16-bit integer from the message buffer.
Definition: nmLibPack.c:1256
static int nmUnpackITVStream(const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, size_t uCount, void *pStruct, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an ITV byte stream.
uint_t m_eMsgId
message id (globally unique)
Definition: netmsgs.h:407
#define NMLIB_RAISE_ERROR(ecode, fmt,...)
Raise libnetmsgs error (i.e. return from calling function).
#define NMCTL_INIT_DECL
Default Internal control declartion list.
#define NM_ECODE_MSGID
bad/unknown message id
Definition: netmsgs.h:78
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
#define NMITV_MSGHDR_SIZE
Definition: netmsgs.h:222
Internal Control Structure.
int nmUnpackITVMsgDebug ( const NMMsgDef_T pMsgDef,
byte_t  buf[],
size_t  uMsgLen,
void *  pStruct,
NMEndian_T  eEndian 
)

Unpack a ITV message, tracing unpacking to stderr.

Parameters
pMsgDefPointer to message definition.
[in]bufInput message buffer.
uMsgLenLength of message (bytes) in input buffer.
[out]pStructPointer to the associated message structure to populate.
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 2419 of file nmLibPackITV.c.

References NMCtl_T::m_bTrace, _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_sMsgName, NM_ECODE_MSGID, NM_ECODE_NOMEM, NMCTL_INIT_DECL, NMITV_MSGHDR_SIZE, NMLIB_RAISE_ERROR, nmPrintBuf(), nmUnpackITVStream(), and nmUnpackU16().

Referenced by nmUnpackPointer().

2424 {
2425  NMCtl_T ctl = NMCTL_INIT_DECL;
2426  ushort_t eMsgId; // message id in buffer
2427  size_t uCount; // field count in buffer
2428  int n; // byte count/error code
2429  int k; // subbyte count/error code
2430 
2431  ctl.m_bTrace = true;
2432 
2433  // too small
2434  if( uMsgLen < NMITV_MSGHDR_SIZE )
2435  {
2436  NMLIB_RAISE_ERROR(NM_ECODE_NOMEM, "%s(%u): msg_len=%u, hdr_size=%u",
2437  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, uMsgLen, NMITV_MSGHDR_SIZE);
2438  }
2439 
2440  // unpack message id
2441  if( (n = nmUnpackU16(buf, uMsgLen, &eMsgId, eEndian)) < 0 )
2442  {
2443  return n;
2444  }
2445 
2446  // field count
2447  uCount = (size_t)buf[n++];
2448 
2449  // mismatch error
2450  if( (uint_t)(pMsgDef->m_eMsgId) != (uint_t)eMsgId )
2451  {
2452  NMLIB_RAISE_ERROR(NM_ECODE_MSGID, "%s(%u): rcv'd msgid=%u != msgdef's",
2453  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, eMsgId);
2454  }
2455 
2456  // trace
2457  fprintf(stderr, "\n--- Unpacking ITV Message %s(%u): field_count=%zu\n",
2458  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, uCount);
2459  fprintf(stderr, "Input Buffer (%zu bytes):\n", uMsgLen);
2460  nmPrintBuf(stderr, NULL, buf, uMsgLen, 16, 0);
2461  fprintf(stderr, "\n");
2462 
2463  // unpack stream
2464  k = nmUnpackITVStream(pMsgDef, &buf[n], uMsgLen-(size_t)n, uCount,
2465  pStruct, eEndian, &ctl);
2466 
2467  // return code
2468  return k>=0? n+k: k;
2469 }
int nmUnpackU16(byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 16-bit integer from the message buffer.
Definition: nmLibPack.c:1256
byte_t m_bTrace
do [not] trace packing/unpacking
static int nmUnpackITVStream(const NMMsgDef_T *pMsgDef, byte_t buf[], size_t uMsgLen, size_t uCount, void *pStruct, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an ITV byte stream.
uint_t m_eMsgId
message id (globally unique)
Definition: netmsgs.h:407
#define NMLIB_RAISE_ERROR(ecode, fmt,...)
Raise libnetmsgs error (i.e. return from calling function).
#define NMCTL_INIT_DECL
Default Internal control declartion list.
#define NM_ECODE_MSGID
bad/unknown message id
Definition: netmsgs.h:78
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
#define NMITV_MSGHDR_SIZE
Definition: netmsgs.h:222
void nmPrintBuf(FILE *fp, const char *sPreface, byte_t buf[], size_t uCount, size_t uNLFreq, uint_t uCol)
Pretty print buffer to opened file stream.
Definition: nmLibUtils.c:138
Internal Control Structure.
INLINE_IN_H int nmUnpackLong ( byte_t  buf[],
size_t  bufSize,
long *  pVal,
NMEndian_T  eEndian 
)

Unpack an signed long integer from the message buffer.

Alias for nmUnpackS32() or nmUnpackS64() depending on sizeof(long).

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 910 of file netmsgs.h.

References nmUnpackS32(), and nmUnpackS64().

912 {
913  return sizeof(ulong_t) == 4?
914  nmUnpackS32(buf, bufSize, (int *)pVal, eEndian):
915  nmUnpackS64(buf, bufSize, (long long *)pVal, eEndian);
916 }
INLINE_IN_H int nmUnpackS32(byte_t buf[], size_t bufSize, int *pVal, NMEndian_T eEndian)
Unpack a signed 32-bit integer from the message buffer.
Definition: netmsgs.h:771
int nmUnpackS64(byte_t buf[], size_t bufSize, long long *pVal, NMEndian_T eEndian)
Unpack an signed 64-bit integer from the message buffer.
Definition: nmLibPack.c:1391
INLINE_IN_H int nmUnpackLongLong ( byte_t  buf[],
size_t  bufSize,
long long *  pVal,
NMEndian_T  eEndian 
)

Unpack an signed long long integer from the message buffer.

Alias for nmUnpackS64().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 940 of file netmsgs.h.

References nmUnpackS64().

942 {
943  return nmUnpackS64(buf, bufSize, (long long *)pVal, eEndian);
944 }
int nmUnpackS64(byte_t buf[], size_t bufSize, long long *pVal, NMEndian_T eEndian)
Unpack an signed 64-bit integer from the message buffer.
Definition: nmLibPack.c:1391
int nmUnpackP32 ( byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian 
)

Unpack a 32-bit pointer from the message buffer.

If the machine architecture has 64-bit pointers, then only the LSB 4 bytes are packed.

Note
Pointer is always unpacked in native byte order.
Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1648 of file nmLibPack.c.

References _NM_CHK_MEM, NMFVAL_LEN_P32, and UNPACKNATIVE.

Referenced by nmPackPointer(), nmUnpackFlatP32(), nmUnpackITVP32(), and nmUnpackPointer().

1649 {
1650  static size_t fvalLen = NMFVAL_LEN_P32; // message field value length
1651 
1652  ulong_t *pluVal; // longs are same size as pointers on 32/64 bit machines
1653  uint_t uP32;
1654 
1655  _NM_CHK_MEM(bufSize, fvalLen);
1656 
1657  pluVal = (ulong_t *)pVal;
1658 
1659  UNPACKNATIVE(buf, &uP32);
1660 
1661  *pluVal = (ulong_t)uP32;
1662 
1663  return (int)fvalLen;
1664 
1665 }
#define UNPACKNATIVE(buf, pval)
Unpack an element from the message buffer in native byte order.
Definition: nmLibPack.c:226
#define NMFVAL_LEN_P32
32-bit pointer field value length
Definition: netmsgs.h:183
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmUnpackP64 ( byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian 
)

Unpack a 64-bit pointer from the message buffer.

If the machine architecture only supports 32-bit pointers, then the 4 MSBs are padded with 0's.

Note
Pointer is always unpacked in native byte order.
Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1678 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, NMFVAL_LEN_P32, NMFVAL_LEN_P64, NMLIB_WARNING, and UNPACK64NATIVE.

Referenced by nmPackPointer(), nmUnpackFlatP64(), nmUnpackITVP64(), and nmUnpackPointer().

1679 {
1680  static size_t fvalLen = NMFVAL_LEN_P64; // message field value length
1681 
1682  uint_t uMSB; // Most Signifcant Bytes
1683  uint_t uLSB; // Least Signifcant Bytes
1684  ulong_t *pluVal; // longs are same size as pointers on 32/64 bit machines
1685 
1686  _NM_CHK_MEM(bufSize, fvalLen);
1687 
1688  pluVal = (ulong_t *)pVal;
1689 
1690  UNPACK64NATIVE(buf, &uMSB, &uLSB);
1691 
1692  // 8-byte pointer
1693  if( sizeof(void *) == fvalLen )
1694  {
1695 #if HOST_WORD_SIZE == 64
1696  *pluVal = (ulong_t)(((ulong_t)uMSB << 32) | (uLSB & 0xffffffff));
1697 #else
1698  *pluVal = (ulong_t)uLSB;
1699 #endif // HOST_WORD_SIZE
1700  }
1701 
1702  // 4-byte pointer
1703  else
1704  {
1705  _NM_CHK_ARCH(pVal, (size_t)NMFVAL_LEN_P32);
1706 
1707  if( uMSB != 0 )
1708  {
1709  NMLIB_WARNING("0x%08x%08x: Unpacking 64-bit pointer into 32 bits "
1710  "lost non-zero significance.\n",
1711  uMSB, uLSB);
1712  }
1713  *pluVal = (ulong_t)uLSB;
1714  }
1715 
1716  return (int)fvalLen;
1717 }
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
#define UNPACK64NATIVE(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in native byte order. ...
Definition: nmLibPack.c:250
#define NMLIB_WARNING(fmt,...)
Log libnetmsgs warning.
Definition: nmLibInternal.h:80
#define NMFVAL_LEN_P32
32-bit pointer field value length
Definition: netmsgs.h:183
#define NMFVAL_LEN_P64
64-bit pointer field value length
Definition: netmsgs.h:184
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
INLINE_IN_H int nmUnpackPointer ( byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian 
)

Unpack a (overloaded)void* pointer from the message buffer.

Alias for nmUnpackP32() or nmUnpackP64() depending on sizeof(void*).

Note
Pointer is always unpacked in native byte order.
Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 956 of file netmsgs.h.

References NMEndianNative, nmGetITVMsgId(), nmPackFlatMsg(), nmPackFlatMsgDebug(), nmPackITVMsg(), nmPackITVMsgDebug(), nmUnpackFlatMsg(), nmUnpackFlatMsgDebug(), nmUnpackITVMsg(), nmUnpackITVMsgDebug(), nmUnpackP32(), and nmUnpackP64().

958 {
959  return sizeof(void*) == 4?
960  nmUnpackP32(buf, bufSize, pVal, NMEndianNative):
961  nmUnpackP64(buf, bufSize, pVal, NMEndianNative);
962 }
native processor order
Definition: netmsgs.h:104
int nmUnpackP64(byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian)
Unpack a 64-bit pointer from the message buffer.
Definition: nmLibPack.c:1678
int nmUnpackP32(byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian)
Unpack a 32-bit pointer from the message buffer.
Definition: nmLibPack.c:1648
INLINE_IN_H int nmUnpackS16 ( byte_t  buf[],
size_t  bufSize,
short *  pVal,
NMEndian_T  eEndian 
)

Unpack a signed 16-bit integer from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 759 of file netmsgs.h.

References nmUnpackU16().

Referenced by nmUnpackFlatS16(), and nmUnpackITVS16().

761 {
762  return nmUnpackU16(buf, bufSize, (ushort_t *)pVal, eEndian);
763 }
int nmUnpackU16(byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 16-bit integer from the message buffer.
Definition: nmLibPack.c:1256
INLINE_IN_H int nmUnpackS32 ( byte_t  buf[],
size_t  bufSize,
int *  pVal,
NMEndian_T  eEndian 
)

Unpack a signed 32-bit integer from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 771 of file netmsgs.h.

References nmUnpackU32().

Referenced by nmUnpackFlatS32(), nmUnpackITVS32(), and nmUnpackLong().

773 {
774  return nmUnpackU32(buf, bufSize, (uint_t *)pVal, eEndian);
775 }
int nmUnpackU32(byte_t buf[], size_t bufSize, uint_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 32-bit integer from the message buffer.
Definition: nmLibPack.c:1288
int nmUnpackS64 ( byte_t  buf[],
size_t  bufSize,
long long *  pVal,
NMEndian_T  eEndian 
)

Unpack an signed 64-bit integer from the message buffer.

If the machine architecture only supports 32-bit long longs, then the 4 MSBs are truncated.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1391 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_S32, NMFVAL_LEN_S64, NMLIB_WARNING, UNPACK64BIG, UNPACK64LITTLE, UNPACK64NATIVE, UNPACKBIG, UNPACKLITTLE, and UNPACKNATIVE.

Referenced by nmPackPointer(), nmUnpackFlatS64(), nmUnpackITVS64(), nmUnpackLong(), and nmUnpackLongLong().

1395 {
1396  static size_t fvalLen = NMFVAL_LEN_S64; // message field value length
1397 
1398  uint_t uMSB; // most significant bytes
1399  uint_t uLSB; // least signifcant bytes
1400 
1401  _NM_CHK_MEM(bufSize, fvalLen);
1402 
1403  // 8-byte unsigned long long
1404  if( sizeof(ulonglong_t) == fvalLen )
1405  {
1406  switch( eEndian )
1407  {
1408  case NMEndianLittle:
1409  UNPACKLITTLE(buf, pVal);
1410  break;
1411  case NMEndianNative:
1412  UNPACKNATIVE(buf, pVal);
1413  break;
1414  case NMEndianBig:
1415  default:
1416  UNPACKBIG(buf, pVal);
1417  break;
1418  }
1419  }
1420 
1421  // 4-byte unsigned long long
1422  else
1423  {
1424  _NM_CHK_ARCH(*pVal, (size_t)NMFVAL_LEN_S32);
1425 
1426  switch( eEndian )
1427  {
1428  case NMEndianLittle:
1429  UNPACK64LITTLE(buf, &uMSB, &uLSB);
1430  break;
1431  case NMEndianNative:
1432  UNPACK64NATIVE(buf, &uMSB, &uLSB);
1433  break;
1434  case NMEndianBig:
1435  default:
1436  UNPACK64BIG(buf, &uMSB, &uLSB);
1437  break;
1438  }
1439 
1440  if( (uMSB != 0) && (uMSB != 0xffffffff) )
1441  {
1442  NMLIB_WARNING("0x%08x%08x: Unpacking signed 64-bit integer into "
1443  "32 bits lost non-zero significance.",
1444  uMSB, uLSB);
1445  }
1446 
1447  *pVal = (long long)uLSB;
1448  }
1449 
1450  return (int)fvalLen;
1451 }
#define UNPACKNATIVE(buf, pval)
Unpack an element from the message buffer in native byte order.
Definition: nmLibPack.c:226
#define NMFVAL_LEN_S32
signed 32-bit field value length
Definition: netmsgs.h:178
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define UNPACK64NATIVE(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in native byte order. ...
Definition: nmLibPack.c:250
#define NMLIB_WARNING(fmt,...)
Log libnetmsgs warning.
Definition: nmLibInternal.h:80
#define UNPACK64BIG(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in big-endian byte order.
Definition: nmLibPack.c:457
#define UNPACK64LITTLE(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in little-endian byte order...
Definition: nmLibPack.c:498
#define UNPACKBIG(buf, pval)
Unpack an element from the message buffer in big-endian byte order.
Definition: nmLibPack.c:405
#define UNPACKLITTLE(buf, pval)
Unpack an element from the message buffer in little-endian byte order.
Definition: nmLibPack.c:421
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
#define NMFVAL_LEN_S64
signed 64-bit field value length
Definition: netmsgs.h:180
INLINE_IN_H int nmUnpackS8 ( byte_t  buf[],
size_t  bufSize,
signed char *  pVal,
NMEndian_T  eEndian 
)

Unpack a signed 8-bit byte from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 747 of file netmsgs.h.

References nmUnpackU8().

Referenced by nmUnpackFlatS8(), and nmUnpackITVS8().

749 {
750  return nmUnpackU8(buf, bufSize, (byte_t *)pVal, eEndian);
751 }
int nmUnpackU8(byte_t buf[], size_t bufSize, byte_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 8-bit byte from the message buffer.
Definition: nmLibPack.c:1239
INLINE_IN_H int nmUnpackSChar ( byte_t  buf[],
size_t  bufSize,
signed char *  pVal,
NMEndian_T  eEndian 
)

Unpack an signed short integer from the message buffer.

Alias for nmUnpackS8().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 799 of file netmsgs.h.

References nmUnpackU8().

801 {
802  return nmUnpackU8(buf, bufSize, (byte_t *)pVal, eEndian);
803 }
int nmUnpackU8(byte_t buf[], size_t bufSize, byte_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 8-bit byte from the message buffer.
Definition: nmLibPack.c:1239
INLINE_IN_H int nmUnpackShort ( byte_t  buf[],
size_t  bufSize,
short *  pVal,
NMEndian_T  eEndian 
)

Unpack an signed short integer from the message buffer.

Alias for nmUnpackS16().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 852 of file netmsgs.h.

References nmUnpackU16().

854 {
855  return nmUnpackU16(buf, bufSize, (ushort_t *)pVal, eEndian);
856 }
int nmUnpackU16(byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 16-bit integer from the message buffer.
Definition: nmLibPack.c:1256
int nmUnpackU16 ( byte_t  buf[],
size_t  bufSize,
ushort_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned 16-bit integer from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1256 of file nmLibPack.c.

References _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_U16, UNPACKBIG, UNPACKLITTLE, and UNPACKNATIVE.

Referenced by nmGetITVMsgId(), nmPackPointer(), nmUnpackFlatU16(), nmUnpackITVMsg(), nmUnpackITVMsgDebug(), nmUnpackITVU16(), nmUnpackS16(), nmUnpackShort(), and nmUnpackUShort().

1260 {
1261  static size_t fvalLen = NMFVAL_LEN_U16; // message field value length
1262 
1263  _NM_CHK_MEM(bufSize, fvalLen);
1264 
1265  switch( eEndian )
1266  {
1267  case NMEndianLittle:
1268  UNPACKLITTLE(buf, pVal);
1269  break;
1270  case NMEndianNative:
1271  UNPACKNATIVE(buf, pVal);
1272  break;
1273  case NMEndianBig:
1274  default:
1275  UNPACKBIG(buf, pVal);
1276  break;
1277  }
1278 
1279  return (int)fvalLen;
1280 }
#define UNPACKNATIVE(buf, pval)
Unpack an element from the message buffer in native byte order.
Definition: nmLibPack.c:226
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define NMFVAL_LEN_U16
unsigned 16-bit field value length
Definition: netmsgs.h:175
#define UNPACKBIG(buf, pval)
Unpack an element from the message buffer in big-endian byte order.
Definition: nmLibPack.c:405
#define UNPACKLITTLE(buf, pval)
Unpack an element from the message buffer in little-endian byte order.
Definition: nmLibPack.c:421
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmUnpackU32 ( byte_t  buf[],
size_t  bufSize,
uint_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned 32-bit integer from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1288 of file nmLibPack.c.

References _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_U32, UNPACKBIG, UNPACKLITTLE, and UNPACKNATIVE.

Referenced by nmPackPointer(), nmUnpackFlatU32(), nmUnpackInt(), nmUnpackITVU32(), nmUnpackS32(), nmUnpackUInt(), and nmUnpackULong().

1289 {
1290  static size_t fvalLen = NMFVAL_LEN_U32; // message field value length
1291 
1292  _NM_CHK_MEM(bufSize, fvalLen);
1293 
1294  switch( eEndian )
1295  {
1296  case NMEndianLittle:
1297  UNPACKLITTLE(buf, pVal);
1298  break;
1299  case NMEndianNative:
1300  UNPACKNATIVE(buf, pVal);
1301  break;
1302  case NMEndianBig:
1303  default:
1304  UNPACKBIG(buf, pVal);
1305  break;
1306  }
1307 
1308  return (int)fvalLen;
1309 }
#define UNPACKNATIVE(buf, pval)
Unpack an element from the message buffer in native byte order.
Definition: nmLibPack.c:226
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define NMFVAL_LEN_U32
unsigned 32-bit field value length
Definition: netmsgs.h:177
#define UNPACKBIG(buf, pval)
Unpack an element from the message buffer in big-endian byte order.
Definition: nmLibPack.c:405
#define UNPACKLITTLE(buf, pval)
Unpack an element from the message buffer in little-endian byte order.
Definition: nmLibPack.c:421
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmUnpackU64 ( byte_t  buf[],
size_t  bufSize,
ulonglong_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned 64-bit integer from the message buffer.

If the machine architecture only supports 32-bit unsigned long longs, then the 4 MSBs are truncated.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1320 of file nmLibPack.c.

References _NM_CHK_ARCH, _NM_CHK_MEM, NMEndianBig, NMEndianLittle, NMEndianNative, NMFVAL_LEN_U32, NMFVAL_LEN_U64, NMLIB_WARNING, UNPACK64BIG, UNPACK64LITTLE, UNPACK64NATIVE, UNPACKBIG, UNPACKLITTLE, and UNPACKNATIVE.

Referenced by nmPackPointer(), nmUnpackFlatU64(), nmUnpackITVU64(), nmUnpackULong(), and nmUnpackULongLong().

1324 {
1325  static size_t fvalLen = NMFVAL_LEN_U64; // message field value length
1326 
1327  uint_t uMSB; // most significant bytes
1328  uint_t uLSB; // least signifcant bytes
1329 
1330  _NM_CHK_MEM(bufSize, fvalLen);
1331 
1332  // 8-byte unsigned long long
1333  if( sizeof(ulonglong_t) == fvalLen )
1334  {
1335  switch( eEndian )
1336  {
1337  case NMEndianLittle:
1338  UNPACKLITTLE(buf, pVal);
1339  break;
1340  case NMEndianNative:
1341  UNPACKNATIVE(buf, pVal);
1342  break;
1343  case NMEndianBig:
1344  default:
1345  UNPACKBIG(buf, pVal);
1346  break;
1347  }
1348  }
1349 
1350  // 4-byte unsigned long long
1351  else
1352  {
1353  _NM_CHK_ARCH(*pVal, (size_t)NMFVAL_LEN_U32);
1354 
1355  switch( eEndian )
1356  {
1357  case NMEndianLittle:
1358  UNPACK64LITTLE(buf, &uMSB, &uLSB);
1359  break;
1360  case NMEndianNative:
1361  UNPACK64NATIVE(buf, &uMSB, &uLSB);
1362  break;
1363  case NMEndianBig:
1364  default:
1365  UNPACK64BIG(buf, &uMSB, &uLSB);
1366  break;
1367  }
1368 
1369  if( uMSB != 0 )
1370  {
1371  NMLIB_WARNING("0x%08x%08x: Unpacking unsigned 64-bit integer into "
1372  "32 bits lost non-zero significance.",
1373  uMSB, uLSB);
1374  }
1375 
1376  *pVal = (ulonglong_t)uLSB;
1377  }
1378 
1379  return (int)fvalLen;
1380 }
#define NMFVAL_LEN_U64
unsigned 64-bit field value length
Definition: netmsgs.h:179
#define UNPACKNATIVE(buf, pval)
Unpack an element from the message buffer in native byte order.
Definition: nmLibPack.c:226
#define _NM_CHK_ARCH(val, size)
Check if host architecture supports basic element sizes.
Definition: nmLibPack.c:724
Most Significant Byte first.
Definition: netmsgs.h:102
native processor order
Definition: netmsgs.h:104
#define UNPACK64NATIVE(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in native byte order. ...
Definition: nmLibPack.c:250
#define NMLIB_WARNING(fmt,...)
Log libnetmsgs warning.
Definition: nmLibInternal.h:80
#define UNPACK64BIG(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in big-endian byte order.
Definition: nmLibPack.c:457
#define UNPACK64LITTLE(buf, puMSB, puLSB)
Unpack two 4-byte unsigned integers from the message buffer in little-endian byte order...
Definition: nmLibPack.c:498
#define NMFVAL_LEN_U32
unsigned 32-bit field value length
Definition: netmsgs.h:177
#define UNPACKBIG(buf, pval)
Unpack an element from the message buffer in big-endian byte order.
Definition: nmLibPack.c:405
#define UNPACKLITTLE(buf, pval)
Unpack an element from the message buffer in little-endian byte order.
Definition: nmLibPack.c:421
Least Significant Byte first.
Definition: netmsgs.h:103
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
int nmUnpackU8 ( byte_t  buf[],
size_t  bufSize,
byte_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned 8-bit byte from the message buffer.

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1239 of file nmLibPack.c.

References _NM_CHK_MEM, and NMFVAL_LEN_U8.

Referenced by nmPackPointer(), nmUnpackBool(), nmUnpackByte(), nmUnpackChar(), nmUnpackFlatU8(), nmUnpackITVU8(), nmUnpackS8(), and nmUnpackSChar().

1240 {
1241  static size_t fvalLen = NMFVAL_LEN_U8; // message field value length
1242 
1243  _NM_CHK_MEM(bufSize, fvalLen);
1244 
1245  *pVal = buf[0];
1246 
1247  return (int)fvalLen;
1248 }
#define NMFVAL_LEN_U8
unsigned 8-bit field value length
Definition: netmsgs.h:172
#define _NM_CHK_MEM(size, count)
Check if memory is available.
Definition: nmLibPack.c:705
INLINE_IN_H int nmUnpackUInt ( byte_t  buf[],
size_t  bufSize,
uint_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned int integer from the message buffer.

Alias for nmUnpackU32().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 866 of file netmsgs.h.

References nmUnpackU32().

868 {
869  return nmUnpackU32(buf, bufSize, (uint_t *)pVal, eEndian);
870 }
int nmUnpackU32(byte_t buf[], size_t bufSize, uint_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 32-bit integer from the message buffer.
Definition: nmLibPack.c:1288
INLINE_IN_H int nmUnpackULong ( byte_t  buf[],
size_t  bufSize,
ulong_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned long integer from the message buffer.

Alias for nmUnpackU32() or nmUnpackU64() depending on sizeof(ulong_t).

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 894 of file netmsgs.h.

References nmUnpackU32(), and nmUnpackU64().

896 {
897  return sizeof(ulong_t) == 4?
898  nmUnpackU32(buf, bufSize, (uint_t *)pVal, eEndian):
899  nmUnpackU64(buf, bufSize, (ulonglong_t *)pVal, eEndian);
900 }
int nmUnpackU64(byte_t buf[], size_t bufSize, ulonglong_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 64-bit integer from the message buffer.
Definition: nmLibPack.c:1320
int nmUnpackU32(byte_t buf[], size_t bufSize, uint_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 32-bit integer from the message buffer.
Definition: nmLibPack.c:1288
INLINE_IN_H int nmUnpackULongLong ( byte_t  buf[],
size_t  bufSize,
ulonglong_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned long long integer from the message buffer.

Alias for nmUnpackU64().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 926 of file netmsgs.h.

References nmUnpackU64().

928 {
929  return nmUnpackU64(buf, bufSize, (ulonglong_t *)pVal, eEndian);
930 }
int nmUnpackU64(byte_t buf[], size_t bufSize, ulonglong_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 64-bit integer from the message buffer.
Definition: nmLibPack.c:1320
INLINE_IN_H int nmUnpackUShort ( byte_t  buf[],
size_t  bufSize,
ushort_t *  pVal,
NMEndian_T  eEndian 
)

Unpack an unsigned short integer from the message buffer.

Alias for nmUnpackU16().

Parameters
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 838 of file netmsgs.h.

References nmUnpackU16().

840 {
841  return nmUnpackU16(buf, bufSize, (ushort_t *)pVal, eEndian);
842 }
int nmUnpackU16(byte_t buf[], size_t bufSize, ushort_t *pVal, NMEndian_T eEndian)
Unpack an unsigned 16-bit integer from the message buffer.
Definition: nmLibPack.c:1256