netmsgs  1.2.2
RoadNarrows Robotics Network Messaging Package
nmLibPackITV.c File Reference

Identifier-Type-Value (ITV) message packing/unpacking definitions. More...

#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/netmsgs.h"
#include "nmLibInternal.h"

Go to the source code of this file.

Macros

#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)   ((ctl)->m_bNoHdr? 0: nmPackITVHdrSimple(p, buf, n))
 Pack simple field type ITV header. More...
 

Functions

static NMPackFunc_T nmLookupITVPacker (NMFType_T eFType)
 Lookup ITV packer function, given the message field type. More...
 
static NMUnpackFunc_T nmLookupITVUnpacker (NMFType_T eFType)
 Lookup ITV unpacker function, given the message field type. More...
 
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. More...
 
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. More...
 
static int nmPackITVHdrSimple (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize)
 Pack ITV simple header. More...
 
static int nmPackITVHdrString (const NMFieldDef_T *pFieldDef, size_t uCount, byte_t buf[], size_t bufSize)
 Pack ITV String header. More...
 
static int nmPackITVHdrStruct (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize)
 Pack ITV Struct header. More...
 
static int nmPackITVHdrVector (const NMFieldDef_T *pFieldDef, size_t uCount, byte_t buf[], size_t bufSize)
 Pack ITV Vector header. More...
 
static int nmPackITVPad (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack pad bytes into the message buffer. More...
 
static int nmPackITVBool (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a boolean into an 8-bit ITV field into the message buffer. More...
 
static int nmPackITVU8 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack an unsigned 8-bit ITV field into the message buffer. More...
 
static int nmPackITVS8 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a signed 8-bit ITV field into the message buffer. More...
 
static int nmPackITVU16 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack an unsigned 16-bit ITV field into the message buffer. More...
 
static int nmPackITVS16 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a signed 16-bit ITV field into the message buffer. More...
 
static int nmPackITVU32 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack an unsigned 32-bit ITV field into the message buffer. More...
 
static int nmPackITVS32 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a signed 32-bit ITV field into the message buffer. More...
 
static int nmPackITVU64 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack an unsigned 64-bit ITV field into the message buffer. More...
 
static int nmPackITVS64 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a signed 64-bit ITV field into the message buffer. More...
 
static int nmPackITVF32 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a 32-bit floating-point number ITV field into the message buffer. More...
 
static int nmPackITVF64 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a 64-bit floating-point number ITV field into the message buffer. More...
 
static int nmPackITVP32 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a 32-bit pointer ITV field into the message buffer. More...
 
static int nmPackITVP64 (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a 64-bit pointer ITV field into the message buffer. More...
 
static int nmPackITVString (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack null-terminated, variable length string ITV field into the message buffer. More...
 
static int nmPackITVStruct (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack a structure ITV field into the message buffer. More...
 
static int nmPackITVVector (const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
 Pack variable length vector ITV field into the message buffer. More...
 
static int nmUnpackITVNoExec (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
 Move parse cursor position past current field in message stream field. More...
 
static int nmUnpackITVPad (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack pad byte from the message buffer. More...
 
static int nmUnpackITVBool (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack an unsigned 8-bit boolean ITV field from the message buffer. More...
 
static int nmUnpackITVU8 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack an unsigned 8-bit ITV field from the message buffer. More...
 
static int nmUnpackITVS8 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a signed 8-bit ITV field from the message buffer. More...
 
static int nmUnpackITVU16 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack an unsigned 16-bit ITV field from the message buffer. More...
 
static int nmUnpackITVS16 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a signed 16-bit ITV field from the message buffer. More...
 
static int nmUnpackITVU32 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack an unsigned 32-bit ITV field from the message buffer. More...
 
static int nmUnpackITVS32 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a signed 32-bit ITV field from the message buffer. More...
 
static int nmUnpackITVU64 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack an unsigned 64-bit ITV field from the message buffer. More...
 
static int nmUnpackITVS64 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a signed 64-bit ITV field from the message buffer. More...
 
static int nmUnpackITVF32 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a 32-bit floating-point number ITV field from the message buffer. More...
 
static int nmUnpackITVF64 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a 64-bit floating-point number ITV field from the message buffer. More...
 
static int nmUnpackITVP32 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a 32-bit pointer ITV field from the message buffer. More...
 
static int nmUnpackITVP64 (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack a 64-bit pointer ITV field from the message buffer. More...
 
static int nmUnpackITVString (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack variable length string ITV field from the message buffer. More...
 
static int nmUnpackITVStruct (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack structure ITV field from the message buffer. More...
 
static int nmUnpackITVVector (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
 Unpack variable length vector ITV field 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...
 

Variables

static NMLookupTblEntry_T NMITVLookupTbl []
 

Detailed Description

Identifier-Type-Value (ITV) message packing/unpacking definitions.

LastChangedDate
2010-07-31 08:48:56 -0600 (Sat, 31 Jul 2010)
Rev
521
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 nmLibPackITV.c.

Macro Definition Documentation

#define ITVPACK_SIMPLE_HDR (   p,
  buf,
  n,
  ctl 
)    ((ctl)->m_bNoHdr? 0: nmPackITVHdrSimple(p, buf, n))

Pack simple field type ITV header.

Parameters
pPointer to message field definition.
[out]bufOutput message buffer.
nSize of output buffer.
ctlInternal control.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 93 of file nmLibPackITV.c.

Referenced by nmPackITVBool(), nmPackITVF32(), nmPackITVF64(), nmPackITVP32(), nmPackITVP64(), nmPackITVS16(), nmPackITVS32(), nmPackITVS64(), nmPackITVS8(), nmPackITVU16(), nmPackITVU32(), nmPackITVU64(), and nmPackITVU8().

Function Documentation

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
static NMPackFunc_T nmLookupITVPacker ( NMFType_T  eFType)
static

Lookup ITV packer function, given the message field type.

Parameters
eFTypeMessage field type.
Returns
Returns packer function on success, NULL on failure.

Definition at line 2174 of file nmLibPackITV.c.

References NMLookupTblEntry_T::m_fnPack, NM_ECODE_INTERNAL, NMHashFType(), NMHashNoIdx, NMLIB_ASCII_FTYPE, and NMLIB_ERROR.

Referenced by nmPackITVStream(), and nmPackITVVector().

2175 {
2176  int idx;
2177 
2178  idx = NMHashFType(eFType);
2179 
2180  if( (idx != NMHashNoIdx) && (idx < arraysize(NMITVLookupTbl)) )
2181  {
2182  if( NMITVLookupTbl[idx].m_eFType == eFType )
2183  {
2184  return NMITVLookupTbl[idx].m_fnPack;
2185  }
2186  else
2187  {
2189  "hashed eFtype='%c'(0x%02x) != tbl[%d].m_eFType='%c'(0x%02x)",
2190  NMLIB_ASCII_FTYPE(eFType), eFType,
2191  idx, NMLIB_ASCII_FTYPE(NMITVLookupTbl[idx].m_eFType),
2192  NMITVLookupTbl[idx].m_eFType);
2193  return NULL;
2194  }
2195  }
2196  else
2197  {
2198  return NULL;
2199  }
2200 }
#define NMLIB_ERROR(ecode, fmt,...)
Log libnetmsgs error.
const int NMHashNoIdx
hash no index value
#define NM_ECODE_INTERNAL
internal inconsistency or bug
Definition: netmsgs.h:80
INLINE_IN_H int NMHashFType(NMFType_T eFType)
Field Type to Index hash function.
#define NMLIB_ASCII_FTYPE(ftype)
Printable ASCII Field Type.
static NMLookupTblEntry_T NMITVLookupTbl[]
NMPackFunc_T m_fnPack
packer
static NMUnpackFunc_T nmLookupITVUnpacker ( NMFType_T  eFType)
static

Lookup ITV unpacker function, given the message field type.

Parameters
eFTypeMessage field type.
Returns
Returns unpacker function on success, NULL on failure.

Definition at line 2209 of file nmLibPackITV.c.

References NMLookupTblEntry_T::m_fnUnpack, NM_ECODE_INTERNAL, NMHashFType(), NMHashNoIdx, NMLIB_ASCII_FTYPE, and NMLIB_ERROR.

Referenced by nmUnpackITVStream(), and nmUnpackITVVector().

2210 {
2211  int idx;
2212 
2213  idx = NMHashFType(eFType);
2214 
2215  if( (idx != NMHashNoIdx) && (idx < arraysize(NMITVLookupTbl)) )
2216  {
2217  if( NMITVLookupTbl[idx].m_eFType == eFType )
2218  {
2219  return NMITVLookupTbl[idx].m_fnUnpack;
2220  }
2221  else
2222  {
2224  "hashed eFtype='%c'(0x%02x) != tbl[%d].m_eFType='%c'(0x%02x)",
2225  NMLIB_ASCII_FTYPE(eFType), eFType,
2226  idx, NMLIB_ASCII_FTYPE(NMITVLookupTbl[idx].m_eFType),
2227  NMITVLookupTbl[idx].m_eFType);
2228  return NULL;
2229  }
2230  }
2231  else
2232  {
2233  return NULL;
2234  }
2235 }
#define NMLIB_ERROR(ecode, fmt,...)
Log libnetmsgs error.
const int NMHashNoIdx
hash no index value
#define NM_ECODE_INTERNAL
internal inconsistency or bug
Definition: netmsgs.h:80
INLINE_IN_H int NMHashFType(NMFType_T eFType)
Field Type to Index hash function.
#define NMLIB_ASCII_FTYPE(ftype)
Printable ASCII Field Type.
static NMLookupTblEntry_T NMITVLookupTbl[]
NMUnpackFunc_T m_fnUnpack
unpacker
static int nmPackITVBool ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a boolean into an 8-bit ITV field into the message buffer.

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

Definition at line 257 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NMLIB_TRACE_FIELD, and nmPackBool().

263 {
264  bool_t val; // constrained field value
265  int n; // byte count/error code
266  int k; // subbyte count/error code
267 
268  val = *((bool_t *)pVal);
269 
270  // try to pack header
271  if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
272  {
273  return n;
274  }
275 
276  // try to pack field value
277  else if( (k = nmPackBool(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
278  {
279  return k;
280  }
281 
282  // success
283  else
284  {
285  n += k;
286 
287  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%s", (val? "true": "false"));
288 
289  return n;
290  }
291 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
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.
Definition: netmsgs.h:564
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
static int nmPackITVF32 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a 32-bit floating-point number ITV field into the message buffer.

Parameters
pFieldDefPointer to message field definition.
[in]pValPointer to (typecasted) value to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
pCtlInternal control.
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 nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackF32(), and nmSetF32().

673 {
674  float val; // constrained field value
675  int n; // byte count/error code
676  int k; // subbyte count/error code
677 
678  // try to set field value
679  if( (n = nmSetF32(pFieldDef, pVal, &val)) != NM_OK )
680  {
681  return n;
682  }
683 
684  // try to pack header
685  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
686  {
687  return n;
688  }
689 
690  // try to pack field value
691  else if( (k = nmPackF32(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
692  {
693  return k;
694  }
695 
696  // success
697  else
698  {
699  n += k;
700 
701  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%f", val);
702 
703  return n;
704  }
705 }
int nmPackF32(float val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack a 32-bit float into the message buffer.
Definition: nmLibPack.c:957
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
int nmSetF32(const NMFieldDef_T *pFieldDef, void *pValIn, float *pValOut)
Helper function to set a 32-bit floating point number.
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
static int nmPackITVF64 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a 64-bit floating-point number ITV field into the message buffer.

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

Definition at line 713 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackF64(), and nmSetF64().

719 {
720  double val; // constrained field value
721  int n; // byte count/error code
722  int k; // subbyte count/error code
723 
724  // try to set field value
725  if( (n = nmSetF64(pFieldDef, pVal, &val)) != NM_OK )
726  {
727  return n;
728  }
729 
730  // try to pack header
731  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
732  {
733  return n;
734  }
735 
736  // try to pack field value
737  else if( (k = nmPackF64(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
738  {
739  return k;
740  }
741 
742  // success
743  else
744  {
745  n += k;
746 
747  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%e", val);
748 
749  return n;
750  }
751 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
int nmSetF64(const NMFieldDef_T *pFieldDef, void *pValIn, double *pValOut)
Helper function to set a 64-bit floating point number.
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
int nmPackF64(double val, byte_t buf[], size_t bufSize, NMEndian_T eEndian)
Pack a 64-bit float into the message buffer.
Definition: nmLibPack.c:1013
static int nmPackITVHdrSimple ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize 
)
static

Pack ITV simple header.

Parameters
pFieldDefPointer to message field definition.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 105 of file nmLibPackITV.c.

References _nm_field_def_struct::m_eFId, _nm_field_def_struct::m_eFType, NM_ECODE_NOMEM, NMITV_FHDR_SIZE_SIMPLE, NMITV_FHDR_SIZE_STRING, and NMLIB_RAISE_FIELD_ERROR.

108 {
109  // pack simple ITV header
110  if( NMITV_FHDR_SIZE_SIMPLE <= bufSize )
111  {
112  buf[0] = (byte_t)(pFieldDef->m_eFId & 0xff);
113  buf[1] = (byte_t)(pFieldDef->m_eFType & 0xff);
114  return NMITV_FHDR_SIZE_SIMPLE;
115  }
116 
117  // no more space in buffer for header
118  else
119  {
121  "buf_size=%zu < fhdr_size=%u", bufSize, NMITV_FHDR_SIZE_STRING);
122  }
123 }
#define NMITV_FHDR_SIZE_STRING
Definition: netmsgs.h:231
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
uint_t m_eFId
filed id (message/struct unique)
Definition: netmsgs.h:382
static int nmPackITVHdrString ( const NMFieldDef_T pFieldDef,
size_t  uCount,
byte_t  buf[],
size_t  bufSize 
)
static

Pack ITV String header.

Parameters
pFieldDefPointer to message field definition.
uCountNumber of character bytes in string.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 135 of file nmLibPackITV.c.

References _nm_field_def_struct::m_eFId, _nm_field_def_struct::m_eFType, NM_ECODE_NOMEM, NMITV_FHDR_SIZE_STRING, and NMLIB_RAISE_FIELD_ERROR.

Referenced by nmPackITVString().

139 {
140  // pack string ITV header
141  if( NMITV_FHDR_SIZE_STRING <= bufSize )
142  {
143  buf[0] = (byte_t)(pFieldDef->m_eFId & 0xff);
144  buf[1] = (byte_t)(pFieldDef->m_eFType & 0xff);
145  buf[2] = (byte_t)(uCount & 0xff);
146  return NMITV_FHDR_SIZE_STRING;
147  }
148 
149  // no more space in buffer for header
150  else
151  {
153  "buf_size=%zu < fhdr_size=%u", bufSize, NMITV_FHDR_SIZE_STRING);
154  }
155 }
#define NMITV_FHDR_SIZE_STRING
Definition: netmsgs.h:231
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
uint_t m_eFId
filed id (message/struct unique)
Definition: netmsgs.h:382
static int nmPackITVHdrStruct ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize 
)
static

Pack ITV Struct header.

Parameters
pFieldDefPointer to message field definition.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 166 of file nmLibPackITV.c.

References _nm_field_def_struct::m_eFId, _nm_field_def_struct::m_eFType, NMFieldThis_T::m_struct, _nm_field_def_struct::m_this, _nm_msg_def_struct::m_uCount, NM_ECODE_NOMEM, NMITV_FHDR_SIZE_STRUCT, and NMLIB_RAISE_FIELD_ERROR.

Referenced by nmPackITVStruct().

169 {
170  // pack struct ITV header
171  if( NMITV_FHDR_SIZE_STRUCT <= bufSize )
172  {
173  buf[0] = (byte_t)(pFieldDef->m_eFId & 0xff);
174  buf[1] = (byte_t)(pFieldDef->m_eFType & 0xff);
175  buf[2] = (byte_t)pFieldDef->m_this.m_struct->m_uCount;
176  return NMITV_FHDR_SIZE_STRUCT;
177  }
178 
179  // no more space in buffer for header
180  else
181  {
183  "buf_size=%zu < fhdr_size=%zu", bufSize, NMITV_FHDR_SIZE_STRUCT);
184  }
185 }
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
size_t m_uCount
number of message fields
Definition: netmsgs.h:408
NMFieldThisStruct_T m_struct
struct field specific info
Definition: netmsgs.h:372
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define NMITV_FHDR_SIZE_STRUCT
Definition: netmsgs.h:234
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
uint_t m_eFId
filed id (message/struct unique)
Definition: netmsgs.h:382
static int nmPackITVHdrVector ( const NMFieldDef_T pFieldDef,
size_t  uCount,
byte_t  buf[],
size_t  bufSize 
)
static

Pack ITV Vector header.

Parameters
pFieldDefPointer to message field definition.
uCountNumber of vector elements.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 197 of file nmLibPackITV.c.

References _nm_field_def_struct::m_eFId, _nm_field_def_struct::m_eFType, NMFieldThisVector_T::m_pThisElem, _nm_field_def_struct::m_this, NMFieldThis_T::m_vector, NM_ECODE_NOMEM, NMITV_FHDR_SIZE_VECTOR, and NMLIB_RAISE_FIELD_ERROR.

Referenced by nmPackITVVector().

201 {
202  // pack vector ITV header
203  if( NMITV_FHDR_SIZE_VECTOR <= bufSize )
204  {
205  buf[0] = (byte_t)(pFieldDef->m_eFId & 0xff);
206  buf[1] = (byte_t)(pFieldDef->m_eFType & 0xff);
207  buf[2] = (byte_t)(uCount & 0xff);
208  buf[3] = (byte_t)pFieldDef->m_this.m_vector.m_pThisElem->m_eFType;
209  return NMITV_FHDR_SIZE_VECTOR;
210  }
211 
212  // no more space in buffer for header
213  else
214  {
216  "buf_size=%zu < fhdr_size=%u", bufSize, NMITV_FHDR_SIZE_VECTOR);
217  }
218 }
NMFieldThisVector_T m_vector
vector field specific info
Definition: netmsgs.h:373
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define NMITV_FHDR_SIZE_VECTOR
Definition: netmsgs.h:237
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
NMFieldDef_P m_pThisElem
vector element specific info
Definition: netmsgs.h:356
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
uint_t m_eFId
filed id (message/struct unique)
Definition: netmsgs.h:382
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.
static int nmPackITVP32 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a 32-bit pointer ITV field into the message buffer.

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

Definition at line 759 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NMLIB_TRACE_FIELD, and nmPackP32().

765 {
766  int n; // byte count/error code
767  int k; // subbyte count/error code
768 
769  // try to pack header
770  if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
771  {
772  return n;
773  }
774 
775  // try to pack field value
776  else if( (k = nmPackP32(pVal, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
777  {
778  return k;
779  }
780 
781  // success
782  else
783  {
784  n += k;
785 
786  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%p", *((ulong_t *)pVal));
787 
788  return n;
789  }
790 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
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
static int nmPackITVP64 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a 64-bit pointer ITV field into the message buffer.

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

Definition at line 798 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NMLIB_TRACE_FIELD, and nmPackP64().

804 {
805  int n; // byte count/error code
806  int k; // subbyte count/error code
807 
808  // try to pack header
809  if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
810  {
811  return n;
812  }
813 
814  // try to pack field value
815  else if( (k = nmPackP64(pVal, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
816  {
817  return k;
818  }
819 
820  // success
821  else
822  {
823  n += k;
824 
825  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%p", *((ulong_t *)pVal));
826 
827  return n;
828  }
829 }
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
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
static int nmPackITVPad ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack pad bytes into the message buffer.

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

Definition at line 226 of file nmLibPackITV.c.

References _nm_field_def_struct::m_eFId, NMFieldThis_T::m_pad, _nm_field_def_struct::m_this, NMFieldThisPad_T::m_uCount, NM_ECODE_NOMEM, NMFVAL_PAD, NMLIB_RAISE_FIELD_ERROR, and NMLIB_TRACE_FIELD.

232 {
233  size_t uCount = pFieldDef->m_this.m_pad.m_uCount;
234 
235  // pack pad bytes
236  if( uCount <= bufSize )
237  {
238  memset(buf, NMFVAL_PAD, uCount);
239  NMLIB_TRACE_FIELD(NULL, buf, uCount, pCtl, "pad(%u)", pFieldDef->m_eFId);
240  return (int)uCount;
241  }
242 
243  // no more space in buffer for pad bytes
244  else
245  {
247  "buf_size=%zu < pad_count=%zu", bufSize, uCount);
248  }
249 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NMFVAL_PAD
pad field value same as tr id
Definition: netmsgs.h:208
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
size_t m_uCount
number of pad bytes
Definition: netmsgs.h:265
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
NMFieldThisPad_T m_pad
pad field specific info
Definition: netmsgs.h:364
uint_t m_eFId
filed id (message/struct unique)
Definition: netmsgs.h:382
static int nmPackITVS16 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a signed 16-bit ITV field into the message buffer.

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

Definition at line 437 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackS16(), and nmSetS16().

443 {
444  short val; // constrained field value
445  int n; // byte count/error code
446  int k; // subbyte count/error code
447 
448  // try to set field value
449  if( (n = nmSetS16(pFieldDef, pVal, &val)) != NM_OK )
450  {
451  return n;
452  }
453 
454  // try to pack header
455  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
456  {
457  return n;
458  }
459 
460  // try to pack field value
461  else if( (k = nmPackS16(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0)
462  {
463  return k;
464  }
465 
466  // success
467  else
468  {
469  n += k;
470 
471  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hd", val);
472 
473  return n;
474  }
475 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
int nmSetS16(const NMFieldDef_T *pFieldDef, void *pValIn, short *pValOut)
Helper function to set a signed 16-bit integer.
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.
Definition: netmsgs.h:500
static int nmPackITVS32 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a signed 32-bit ITV field into the message buffer.

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

Definition at line 529 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackS32(), and nmSetS32().

535 {
536  int val; // constrained field value
537  int n; // byte count/error code
538  int k; // subbyte count/error code
539 
540  // try to set field value
541  if( (n = nmSetS32(pFieldDef, pVal, &val)) != NM_OK )
542  {
543  return n;
544  }
545 
546  // try to pack header
547  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
548  {
549  return n;
550  }
551 
552  // try to pack field value
553  else if( (k = nmPackS32(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
554  {
555  return k;
556  }
557 
558  // success
559  else
560  {
561  n += k;
562 
563  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%d", val);
564 
565  return n;
566  }
567 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
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
int nmSetS32(const NMFieldDef_T *pFieldDef, void *pValIn, int *pValOut)
Helper function to set a signed 32-bit integer.
static int nmPackITVS64 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a signed 64-bit ITV field into the message buffer.

Parameters
pFieldDefPointer to message field definition.
[in]pValPointer to (typecasted) value to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
pCtlInternal control.
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 nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackS64(), and nmSetS64().

627 {
628  long long val; // constrained field value
629  int n; // byte count/error code
630  int k; // subbyte count/error code
631 
632  // try to set field value
633  if( (n = nmSetS64(pFieldDef, pVal, &val)) != NM_OK )
634  {
635  return n;
636  }
637 
638  // try to pack header
639  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
640  {
641  return n;
642  }
643 
644  // try to pack field value
645  else if( (k = nmPackS64(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
646  {
647  return k;
648  }
649 
650  // success
651  else
652  {
653  n += k;
654 
655  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%lld", val);
656 
657  return n;
658  }
659 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
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 nmSetS64(const NMFieldDef_T *pFieldDef, void *pValIn, long long *pValOut)
Helper function to set a signed 64-bit integer.
static int nmPackITVS8 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a signed 8-bit ITV field into the message buffer.

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

Definition at line 345 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackS8(), and nmSetS8().

351 {
352  signed char val; // constrained field value
353  int n; // byte count/error code
354  int k; // subbyte count/error code
355 
356  // try to set field value
357  if( (n = nmSetS8(pFieldDef, pVal, &val)) != NM_OK )
358  {
359  return n;
360  }
361 
362  // try to pack header
363  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
364  {
365  return n;
366  }
367 
368  // try to pack field value
369  else if( (k = nmPackS8(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
370  {
371  return k;
372  }
373 
374  // success
375  else
376  {
377  n += k;
378 
379  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hhd", val);
380 
381  return n;
382  }
383 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
int nmSetS8(const NMFieldDef_T *pFieldDef, void *pValIn, signed char *pValOut)
Helper function to set a signed 8-bit integer.
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
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.
Definition: netmsgs.h:488
static int nmPackITVStream ( const NMMsgDef_T pMsgDef,
void *  pStruct,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a 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.
pCtlPointer to Internal control.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1035 of file nmLibPackITV.c.

References _nm_field_def_struct::m_eFType, _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_pFields, _nm_field_def_struct::m_uOffset, NM_ECODE_FTYPE, NM_ECODE_NOMEM, NMFTypePad, NMLIB_ASCII_FTYPE, NMLIB_RAISE_ERROR, NMLIB_RAISE_FIELD_ERROR, and nmLookupITVPacker().

Referenced by nmPackITVMsg(), nmPackITVMsgDebug(), and nmPackITVStruct().

1041 {
1042  size_t uFieldNum;
1043  const NMFieldDef_T *pFieldDef;
1044  NMPackFunc_T fnPack = NULL;
1045  void *pVal;
1046  int n = 0;
1047  int k;
1048 
1049  //
1050  // Pack message fields
1051  //
1052  for(uFieldNum=0, pFieldDef=pMsgDef->m_pFields;
1053  uFieldNum < pMsgDef->m_uCount;
1054  ++uFieldNum, ++pFieldDef)
1055  {
1056  if( n < bufSize )
1057  {
1058  if( pFieldDef->m_eFType == NMFTypePad )
1059  {
1060  pVal = NULL;
1061  }
1062 
1063  else
1064  {
1065  pVal = pStruct + pFieldDef->m_uOffset;
1066  }
1067 
1068  fnPack = nmLookupITVPacker(pFieldDef->m_eFType);
1069 
1070  if( fnPack == NULL )
1071  {
1073  "ftype='%c'(0x%02x).",
1074  NMLIB_ASCII_FTYPE(pFieldDef->m_eFType), pFieldDef->m_eFType);
1075  }
1076 
1077  k = fnPack(pFieldDef, pVal, &buf[n], bufSize-(size_t)n, eEndian, pCtl);
1078 
1079  if( k < 0 )
1080  {
1081  return k;
1082  }
1083  }
1084 
1085  else
1086  {
1088  "buf_size=%zu, msgid=%u", bufSize, pMsgDef->m_eMsgId);
1089  }
1090 
1091  n += k;
1092  }
1093 
1094  return n;
1095 }
static NMPackFunc_T nmLookupITVPacker(NMFType_T eFType)
Lookup ITV packer function, given the message field type.
#define NM_ECODE_FTYPE
unknown field type
Definition: netmsgs.h:76
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
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 NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
int(* NMPackFunc_T)(const NMFieldDef_T *, void *, byte_t[], size_t, NMEndian_T, NMCtl_T *)
const NMFieldDef_T * m_pFields
pointer to array of msg field definitions
Definition: netmsgs.h:409
pad internal field type
Definition: netmsgs.h:145
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NMLIB_ASCII_FTYPE(ftype)
Printable ASCII Field Type.
size_t m_uOffset
member offset in assoc msg structure
Definition: netmsgs.h:384
static int nmPackITVString ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack null-terminated, variable length string ITV field into the message buffer.

Note
The null character is not packed.
Parameters
pFieldDefPointer to message field definition.
[in]pValPointer to (typecasted) value to pack.
[out]bufOutput message buffer.
bufSizeSize of output buffer.
eEndianPacking order. See NMEndian_T.
pCtlInternal control.
Returns
On success, returns the number of bytes packed. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 840 of file nmLibPackITV.c.

References NMFieldThisString_T::m_sConst, NMFieldThis_T::m_string, _nm_field_def_struct::m_this, NMFieldThisString_T::m_uMaxCount, NM_ECODE_NOMEM, NM_ECODE_RANGE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, and nmPackITVHdrString().

846 {
847  const char *sVal;
848  const char *sConst;
849  size_t uMaxCount;
850  size_t uCount;
851  int n = 0;
852 
853  sVal = (const char *)pVal; // override value pointer type
854  sConst = pFieldDef->m_this.m_string.m_sConst;
855  uMaxCount = pFieldDef->m_this.m_string.m_uMaxCount;
856 
857  if( sConst != NULL )
858  {
859  sVal = sConst;
860  }
861 
862  uCount = strlen(sVal); // string length w/o null
863 
864  // string length exceeds maximum
865  if( uCount > uMaxCount )
866  {
868  "char_count=%zu > max_count=%zu.", uCount, uMaxCount);
869  }
870 
871  // try to pack ITV header
872  if( (n = nmPackITVHdrString(pFieldDef, uCount, buf, bufSize)) < 0 )
873  {
874  return n;
875  }
876 
877  // no more space in buffer for string
878  else if( uCount > bufSize-(size_t)n )
879  {
881  "buf_size=%zu < str_len=%zu.", bufSize, uCount);
882  }
883 
884  // copy string field value
885  else
886  {
887  memcpy(&buf[n], sVal, uCount);
888 
889  n += (int)uCount;
890 
891  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "'%s'", sVal);
892 
893  return n;
894  }
895 }
NMFieldThisString_T m_string
string field specific info
Definition: netmsgs.h:371
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
size_t m_uMaxCount
maximum number of characters sans null char
Definition: netmsgs.h:339
static int nmPackITVHdrString(const NMFieldDef_T *pFieldDef, size_t uCount, byte_t buf[], size_t bufSize)
Pack ITV String header.
Definition: nmLibPackITV.c:135
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
const char * m_sConst
string constant value (NULL if no const)
Definition: netmsgs.h:340
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NM_ECODE_RANGE
field size or value out-of-range
Definition: netmsgs.h:75
static int nmPackITVStruct ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack a structure ITV field into the message buffer.

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

Definition at line 903 of file nmLibPackITV.c.

References _nm_msg_def_struct::m_sMsgName, NMFieldThis_T::m_struct, _nm_field_def_struct::m_this, _nm_msg_def_struct::m_uCount, NMCtl_T::m_uDepth, NMLIB_TRACE_FIELD, nmPackITVHdrStruct(), and nmPackITVStream().

909 {
910  const NMMsgDef_T *pStructDef;
911  int n = 0;
912  int k;
913 
914  pStructDef = pFieldDef->m_this.m_struct;
915 
916  // try to pack ITV header
917  if( (n = nmPackITVHdrStruct(pFieldDef, buf, bufSize)) < 0 )
918  {
919  return n;
920  }
921 
922  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "structdef %s, member_count=%zu",
923  pStructDef->m_sMsgName, pStructDef->m_uCount);
924 
925  pCtl->m_uDepth++;
926 
927  // copy struct field value
928  k = nmPackITVStream(pStructDef, pVal, &buf[n], bufSize-(size_t)n, eEndian,
929  pCtl);
930 
931  pCtl->m_uDepth--;
932 
933  return k>=0? n+k: k;
934 }
byte_t m_uDepth
structured message depth
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
size_t m_uCount
number of message fields
Definition: netmsgs.h:408
NMFieldThisStruct_T m_struct
struct field specific info
Definition: netmsgs.h:372
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
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.
static int nmPackITVHdrStruct(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize)
Pack ITV Struct header.
Definition: nmLibPackITV.c:166
static int nmPackITVU16 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack an unsigned 16-bit ITV field into the message buffer.

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

Definition at line 391 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackU16(), and nmSetU16().

397 {
398  ushort_t val; // constrained field value
399  int n; // byte count/error code
400  int k; // subbyte count/error code
401 
402  // try to set field value
403  if( (n = nmSetU16(pFieldDef, pVal, &val)) != NM_OK )
404  {
405  return n;
406  }
407 
408  // try to pack header
409  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
410  {
411  return n;
412  }
413 
414  // try to pack field value
415  else if( (k = nmPackU16(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
416  {
417  return k;
418  }
419 
420  // success
421  else
422  {
423  n += k;
424 
425  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hu", val);
426 
427  return n;
428  }
429 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
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 nmSetU16(const NMFieldDef_T *pFieldDef, void *pValIn, ushort_t *pValOut)
Helper function to set an unsigned 16-bit integer.
static int nmPackITVU32 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack an unsigned 32-bit ITV field into the message buffer.

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

Definition at line 483 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackU32(), and nmSetU32().

489 {
490  uint_t val; // constrained field value
491  int n; // byte count/error code
492  int k; // subbyte count/error code
493 
494  // try to set field value
495  if( (n = nmSetU32(pFieldDef, pVal, &val)) != NM_OK )
496  {
497  return n;
498  }
499 
500  // try to pack header
501  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
502  {
503  return n;
504  }
505 
506  // try to pack field value
507  else if( (k = nmPackU32(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
508  {
509  return k;
510  }
511 
512  // success
513  else
514  {
515  n += k;
516 
517  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%u", val);
518 
519  return n;
520  }
521 }
int nmSetU32(const NMFieldDef_T *pFieldDef, void *pValIn, uint_t *pValOut)
Helper function to set an unsigned 32-bit integer.
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
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
static int nmPackITVU64 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack an unsigned 64-bit ITV field into the message buffer.

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

Definition at line 575 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackU64(), and nmSetU64().

581 {
582  ulonglong_t val; // constrained field value
583  int n; // byte count/error code
584  int k; // subbyte count/error code
585 
586  // try to set field value
587  if( (n = nmSetU64(pFieldDef, pVal, &val)) != NM_OK )
588  {
589  return n;
590  }
591 
592  // try to pack header
593  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
594  {
595  return n;
596  }
597 
598  // try to pack field value
599  else if( (k = nmPackU64(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
600  {
601  return k;
602  }
603 
604  // success
605  else
606  {
607  n += k;
608 
609  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%llu", val);
610 
611  return n;
612  }
613 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
int nmSetU64(const NMFieldDef_T *pFieldDef, void *pValIn, ulonglong_t *pValOut)
Helper function to set an unsigned 64-bit integer.
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
static int nmPackITVU8 ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack an unsigned 8-bit ITV field into the message buffer.

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

Definition at line 299 of file nmLibPackITV.c.

References ITVPACK_SIMPLE_HDR, NM_OK, NMLIB_TRACE_FIELD, nmPackU8(), and nmSetU8().

305 {
306  byte_t val; // constrained field value
307  int n; // byte count/error code
308  int k; // subbyte count/error code
309 
310  // try to set field value
311  if( (n = nmSetU8(pFieldDef, pVal, &val)) != NM_OK )
312  {
313  return n;
314  }
315 
316  // try to pack header
317  else if( (n = ITVPACK_SIMPLE_HDR(pFieldDef, buf, bufSize, pCtl)) < 0 )
318  {
319  return n;
320  }
321 
322  // try to pack field value
323  else if( (k = nmPackU8(val, &buf[n], bufSize-(size_t)n, eEndian)) < 0 )
324  {
325  return k;
326  }
327 
328  // success
329  else
330  {
331  n += k;
332 
333  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hhu", val);
334 
335  return n;
336  }
337 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_OK
not an error, success
Definition: netmsgs.h:70
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 nmSetU8(const NMFieldDef_T *pFieldDef, void *pValIn, byte_t *pValOut)
Helper function to set an unsigned 8-bit integer.
#define ITVPACK_SIMPLE_HDR(p, buf, n, ctl)
Pack simple field type ITV header.
Definition: nmLibPackITV.c:93
static int nmPackITVVector ( const NMFieldDef_T pFieldDef,
void *  pVal,
byte_t  buf[],
size_t  bufSize,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Pack variable length vector ITV field into the message buffer.

A vector is a one-dimension array of the given type.

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

Definition at line 944 of file nmLibPackITV.c.

References NMCtl_T::m_bNoHdr, NMVec_T::m_buf, _nm_field_def_struct::m_eFType, NMFieldThisVector_T::m_pThisElem, _nm_field_def_struct::m_this, NMVec_T::m_uCount, NMCtl_T::m_uDepth, NMFieldThisVector_T::m_uElemSize, NMFieldThisVector_T::m_uMaxCount, NMFieldThis_T::m_vector, NM_ECODE_FTYPE, NM_ECODE_RANGE, NMFTYPE_IS_SIMPLE, NMLIB_ASCII_FTYPE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmLookupITVPacker(), and nmPackITVHdrVector().

950 {
951  size_t uMaxCount;
952  size_t uElemSize;
953  const NMFieldDef_T *pElemDef;
954  NMVec_T *pVec;
955  size_t uCount;
956  byte_t *pItem;
957  NMPackFunc_T fnPack = NULL;
958  int n = 0;
959  int k;
960  size_t i;
961 
962  uMaxCount = pFieldDef->m_this.m_vector.m_uMaxCount;
963  uElemSize = pFieldDef->m_this.m_vector.m_uElemSize;
964  pElemDef = pFieldDef->m_this.m_vector.m_pThisElem;
965  pVec = (NMVec_T *)pVal; // generalized vector overlay
966  uCount = pVec->m_uCount; // number of vector items
967  pItem = (byte_t *)(pVec) + memberoffset(NMVec_T, u.m_buf);
968  fnPack = nmLookupITVPacker(pElemDef->m_eFType);
969 
970  if( fnPack == NULL )
971  {
973  "vector_elem_ftype='%c'(0x%02x)",
974  NMLIB_ASCII_FTYPE(pElemDef->m_eFType), pElemDef->m_eFType);
975  }
976 
977  // exceeds maximum
978  else if( uCount > uMaxCount )
979  {
981  "vector_count=%zu > max_count=%zu.", uCount, uMaxCount);
982  }
983 
984  // try to pack ITV header
985  else if( (n = nmPackITVHdrVector(pFieldDef, uCount, buf, bufSize)) < 0 )
986  {
987  return n;
988  }
989 
990  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%c:vector[%zu]",
991  pElemDef->m_eFType, uCount);
992 
993  // no header for simple vector element types
994  if( NMFTYPE_IS_SIMPLE(pElemDef->m_eFType) )
995  {
996  pCtl->m_bNoHdr = true;
997  }
998 
999  pCtl->m_uDepth++;
1000 
1001  // copy vector field value
1002  for(i=0; i<uCount; ++i)
1003  {
1004  k = fnPack(pElemDef, pItem, &buf[n], bufSize-(size_t)n, eEndian, pCtl);
1005 
1006  if( k < 0 )
1007  {
1008  return k;
1009  }
1010 
1011  n += k;
1012 
1013  pItem += uElemSize;
1014  }
1015 
1016  pCtl->m_uDepth--;
1017  pCtl->m_bNoHdr = false;
1018 
1019  return n;
1020 }
byte_t m_bNoHdr
do [not] include field header in byte stream
static NMPackFunc_T nmLookupITVPacker(NMFType_T eFType)
Lookup ITV packer function, given the message field type.
byte_t m_uDepth
structured message depth
size_t m_uMaxCount
maximum number of vector elements
Definition: netmsgs.h:354
static int nmPackITVHdrVector(const NMFieldDef_T *pFieldDef, size_t uCount, byte_t buf[], size_t bufSize)
Pack ITV Vector header.
Definition: nmLibPackITV.c:197
NMFieldThisVector_T m_vector
vector field specific info
Definition: netmsgs.h:373
#define NM_ECODE_FTYPE
unknown field type
Definition: netmsgs.h:76
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
#define NMFTYPE_IS_SIMPLE(ft)
Returns true if field type is a simple type.
Definition: netmsgs.h:164
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
int(* NMPackFunc_T)(const NMFieldDef_T *, void *, byte_t[], size_t, NMEndian_T, NMCtl_T *)
NMFieldDef_P m_pThisElem
vector element specific info
Definition: netmsgs.h:356
size_t m_uElemSize
vector element storage size
Definition: netmsgs.h:355
size_t m_uCount
number of items in vector
Definition: netmsgs.h:393
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NMLIB_ASCII_FTYPE(ftype)
Printable ASCII Field Type.
#define NM_ECODE_RANGE
field size or value out-of-range
Definition: netmsgs.h:75
byte_t * m_buf
the vector
Definition: netmsgs.h:397
static int nmUnpackITVBool ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack an unsigned 8-bit boolean ITV field from the message buffer.

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

Definition at line 1164 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_U8, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackBool(), and nmUnpackITVNoExec().

1170 {
1171  int n; // byte count/error code
1172  int k; // subbyte count/error code
1173 
1174  // header size
1175  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1176 
1177  // not enough input buffer for header
1178  if( n > bufSize )
1179  {
1181  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1182  }
1183 
1184  // ignore this field
1185  else if( pCtl->m_bNoExec )
1186  {
1187  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_U8,
1188  pCtl);
1189  }
1190 
1191  // try to unpack value
1192  else if( (k = nmUnpackBool(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1193  {
1194  return k;
1195  }
1196 
1197  // success
1198  else
1199  {
1200  n += k;
1201 
1202  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%s",
1203  (*((bool_t *)pVal)? "true": "false"));
1204 
1205  return n;
1206  }
1207 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
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.
Definition: netmsgs.h:823
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NMFVAL_LEN_U8
unsigned 8-bit field value length
Definition: netmsgs.h:172
static int nmUnpackITVF32 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a 32-bit floating-point number ITV field from the message buffer.

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

Definition at line 1618 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_F32, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackF32(), and nmUnpackITVNoExec().

1624 {
1625  int n; // byte count/error code
1626  int k; // subbyte count/error code
1627 
1628  // header size
1629  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1630 
1631  // not enough input buffer for header
1632  if( n > bufSize )
1633  {
1635  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1636  }
1637 
1638  // ignore this field
1639  else if( pCtl->m_bNoExec )
1640  {
1641  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_F32,
1642  pCtl);
1643  }
1644 
1645  // try to unpack value
1646  else if( (k = nmUnpackF32(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1647  {
1648  return k;
1649  }
1650 
1651  // success
1652  else
1653  {
1654  n += k;
1655 
1656  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%f", *((float *)pVal));
1657 
1658  return n;
1659  }
1660 }
byte_t m_bNoHdr
do [not] include field header in byte stream
int nmUnpackF32(byte_t buf[], size_t bufSize, float *pVal, NMEndian_T eEndian)
Unpack a 32-bit float from the message buffer.
Definition: nmLibPack.c:1472
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
#define NMFVAL_LEN_F32
32-bit floating-point number field val len
Definition: netmsgs.h:181
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVF64 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a 64-bit floating-point number ITV field from the message buffer.

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

Definition at line 1669 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_F64, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackF64(), and nmUnpackITVNoExec().

1675 {
1676  int n; // byte count/error code
1677  int k; // subbyte count/error code
1678 
1679  // header size
1680  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1681 
1682  // not enough input buffer for header
1683  if( n > bufSize )
1684  {
1686  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1687  }
1688 
1689  // ignore this field
1690  else if( pCtl->m_bNoExec )
1691  {
1692  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_F64,
1693  pCtl);
1694  }
1695 
1696  // try to unpack value
1697  else if( (k = nmUnpackF64(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1698  {
1699  return k;
1700  }
1701 
1702  // success
1703  else
1704  {
1705  n += k;
1706 
1707  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%e", *((double *)pVal));
1708 
1709  return n;
1710  }
1711 }
byte_t m_bNoHdr
do [not] include field header in byte stream
int nmUnpackF64(byte_t buf[], size_t bufSize, double *pVal, NMEndian_T eEndian)
Unpack a 64-bit float from the message buffer.
Definition: nmLibPack.c:1517
#define NMFVAL_LEN_F64
64-bit floating-point number field val len
Definition: netmsgs.h:182
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
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.
static int nmUnpackITVNoExec ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
size_t  uFLen,
NMCtl_T pCtl 
)
static

Move parse cursor position past current field in message stream field.

No unpacking field into an output variable is executed.

Parameters
pFieldDefPointer to message field definition.
[in]bufInput message buffer.
bufSizeSize of input buffer.
uFLenLength of field (bytes).
pCtlPointer to Internal control.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1115 of file nmLibPackITV.c.

References NM_ECODE_NOMEM, NMLIB_RAISE_FIELD_ERROR, and NMLIB_TRACE_FIELD.

Referenced by nmUnpackITVBool(), nmUnpackITVF32(), nmUnpackITVF64(), nmUnpackITVP32(), nmUnpackITVP64(), nmUnpackITVS16(), nmUnpackITVS32(), nmUnpackITVS64(), nmUnpackITVS8(), nmUnpackITVU16(), nmUnpackITVU32(), nmUnpackITVU64(), and nmUnpackITVU8().

1120 {
1121  if( uFLen > bufSize )
1122  {
1124  "buf_size=%zu < flen=%zu", bufSize, uFLen);
1125  }
1126 
1127  NMLIB_TRACE_FIELD(pFieldDef, buf, uFLen, pCtl, "ignore");
1128 
1129  return (int)uFLen;
1130 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVP32 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a 32-bit pointer ITV field from the message buffer.

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

Definition at line 1719 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_P32, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackP32().

1725 {
1726  int n; // byte count/error code
1727  int k; // subbyte count/error code
1728 
1729  // header size
1730  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1731 
1732  // not enough input buffer for header
1733  if( n > bufSize )
1734  {
1736  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1737  }
1738 
1739  // ignore this field
1740  else if( pCtl->m_bNoExec )
1741  {
1742  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_P32,
1743  pCtl);
1744  }
1745 
1746  // try to unpack value
1747  else if( (k = nmUnpackP32(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1748  {
1749  return k;
1750  }
1751 
1752  // success
1753  else
1754  {
1755  n += k;
1756 
1757  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%p", *((ulong_t *)pVal));
1758 
1759  return n;
1760  }
1761 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NMFVAL_LEN_P32
32-bit pointer field value length
Definition: netmsgs.h:183
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
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
static int nmUnpackITVP64 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a 64-bit pointer ITV field from the message buffer.

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

Definition at line 1769 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_P64, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackP64().

1775 {
1776  int n; // byte count/error code
1777  int k; // subbyte count/error code
1778 
1779  // header size
1780  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1781 
1782  // not enough input buffer for header
1783  if( n > bufSize )
1784  {
1786  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1787  }
1788 
1789  // ignore this field
1790  else if( pCtl->m_bNoExec )
1791  {
1792  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_P64,
1793  pCtl);
1794  }
1795 
1796  // try to unpack value
1797  else if( (k = nmUnpackP64(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1798  {
1799  return k;
1800  }
1801 
1802  // success
1803  else
1804  {
1805  n += k;
1806 
1807  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%p", *((ulong_t *)pVal));
1808 
1809  return n;
1810  }
1811 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMFVAL_LEN_P64
64-bit pointer field value length
Definition: netmsgs.h:184
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
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
static int nmUnpackITVPad ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack pad byte from the message buffer.

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

Definition at line 1138 of file nmLibPackITV.c.

References NMFVAL_PAD, and NMLIB_TRACE_FIELD.

1144 {
1145  int n = 0;
1146 
1147  // skip over all pad bytes
1148  while( (buf[n] == NMFVAL_PAD) && (n < bufSize) )
1149  {
1150  ++n;
1151  }
1152 
1153  NMLIB_TRACE_FIELD(NULL, buf, n, pCtl, "pad");
1154 
1155  return n;
1156 }
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
#define NMFVAL_PAD
pad field value same as tr id
Definition: netmsgs.h:208
static int nmUnpackITVS16 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a signed 16-bit ITV field from the message buffer.

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

Definition at line 1366 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_S16, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackS16().

1372 {
1373  int n; // byte count/error code
1374  int k; // subbyte count/error code
1375 
1376  // header size
1377  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1378 
1379  // not enough input buffer for header
1380  if( n > bufSize )
1381  {
1383  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1384  }
1385 
1386  // ignore this field
1387  else if( pCtl->m_bNoExec )
1388  {
1389  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_S16,
1390  pCtl);
1391  }
1392 
1393  // try to unpack value
1394  else if( (k = nmUnpackS16(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1395  {
1396  return k;
1397  }
1398 
1399  // success
1400  else
1401  {
1402  n += k;
1403 
1404  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hd", *((short *)pVal));
1405 
1406  return n;
1407  }
1408 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
#define NMFVAL_LEN_S16
signed 16-bit field value length
Definition: netmsgs.h:176
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
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.
Definition: netmsgs.h:759
static int nmUnpackITVS32 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a signed 32-bit ITV field from the message buffer.

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

Definition at line 1466 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_S32, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackS32().

1472 {
1473  int n; // byte count/error code
1474  int k; // subbyte count/error code
1475 
1476  // header size
1477  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1478 
1479  // not enough input buffer for header
1480  if( n > bufSize )
1481  {
1483  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1484  }
1485 
1486  // ignore this field
1487  else if( pCtl->m_bNoExec )
1488  {
1489  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_S32,
1490  pCtl);
1491  }
1492 
1493  // try to unpack value
1494  else if( (k = nmUnpackS32(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1495  {
1496  return k;
1497  }
1498 
1499  // success
1500  else
1501  {
1502  n += k;
1503 
1504  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%d", *((int *)pVal));
1505 
1506  return n;
1507  }
1508 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMFVAL_LEN_S32
signed 32-bit field value length
Definition: netmsgs.h:178
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
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVS64 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a signed 64-bit ITV field from the message buffer.

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

Definition at line 1567 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_S64, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackS64().

1573 {
1574  int n; // byte count/error code
1575  int k; // subbyte count/error code
1576 
1577  // header size
1578  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1579 
1580  // not enough input buffer for header
1581  if( n > bufSize )
1582  {
1584  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1585  }
1586 
1587  // ignore this field
1588  else if( pCtl->m_bNoExec )
1589  {
1590  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_S64,
1591  pCtl);
1592  }
1593 
1594  // try to unpack value
1595  else if( (k = nmUnpackS64(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1596  {
1597  return k;
1598  }
1599 
1600  // success
1601  else
1602  {
1603  n += k;
1604 
1605  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%lld", *((long long *)pVal));
1606 
1607  return n;
1608  }
1609 }
byte_t m_bNoHdr
do [not] include field header in byte stream
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
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NMFVAL_LEN_S64
signed 64-bit field value length
Definition: netmsgs.h:180
static int nmUnpackITVS8 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack a signed 8-bit ITV field from the message buffer.

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

Definition at line 1265 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_S8, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackS8().

1271 {
1272  int n; // byte count/error code
1273  int k; // subbyte count/error code
1274 
1275  // header size
1276  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1277 
1278  // not enough input buffer for header
1279  if( n > bufSize )
1280  {
1282  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1283  }
1284 
1285  // ignore this field
1286  else if( pCtl->m_bNoExec )
1287  {
1288  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_S8,
1289  pCtl);
1290  }
1291 
1292  // try to unpack value
1293  else if( (k = nmUnpackS8(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1294  {
1295  return k;
1296  }
1297 
1298  // success
1299  else
1300  {
1301  n += k;
1302 
1303  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hhd",
1304  *((signed char *)pVal));
1305 
1306  return n;
1307  }
1308 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMFVAL_LEN_S8
signed 8-bit field value length
Definition: netmsgs.h:173
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
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.
Definition: netmsgs.h:747
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVStream ( const NMMsgDef_T pMsgDef,
byte_t  buf[],
size_t  uMsgLen,
size_t  uCount,
void *  pStruct,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack an ITV byte stream.

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.
uCountReceived message/struct field count
eEndianUnpacking order. See NMEndian_T.
pCtlPointer to Internal control.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 2043 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, _nm_field_def_struct::m_eFType, _nm_msg_def_struct::m_eMsgId, _nm_msg_def_struct::m_sMsgName, _nm_field_def_struct::m_uOffset, NM_ECODE_EMSG, NM_ECODE_FTYPE, NM_ECODE_NOMEM, nmFindFieldDef(), NMFTypePad, NMFTypePadTr, NMITV_FHDR_SIZE_BASE, NMITV_FID_SIZE, NMLIB_ASCII_FTYPE, NMLIB_RAISE_ERROR, NMLIB_RAISE_FIELD_ERROR, NMLIB_WARNING, and nmLookupITVUnpacker().

Referenced by nmUnpackITVMsg(), nmUnpackITVMsgDebug(), and nmUnpackITVStruct().

2050 {
2051  const NMFieldDef_T *pFieldDef;
2052  NMUnpackFunc_T fnUnpack = NULL;
2053  byte_t bNoExec;
2054  byte_t byFId;
2055  byte_t byFType;
2056  void *pVal;
2057  int n = 0;
2058  int k;
2059 
2060  bNoExec = pCtl->m_bNoExec;
2061 
2062  while( (uCount > 0) && (n+NMITV_FID_SIZE < uMsgLen) )
2063  {
2064  byFId = buf[n]; // field id
2065 
2066  // Padding (reserved packed id)
2067  if( byFId == NMFTypePadTr )
2068  {
2069  byFType = (byte_t)NMFTypePad; // internal pad field type
2070  pFieldDef = NULL;
2071  pVal = NULL;
2072  }
2073 
2074  // ITV field
2075  else
2076  {
2077  if( n+NMITV_FHDR_SIZE_BASE >= uMsgLen )
2078  {
2080  "msg_len=%zu, msg_id=%u", uMsgLen, pMsgDef->m_eMsgId);
2081  }
2082 
2083  byFType = buf[n+1]; // field type
2084 
2085  if( (pFieldDef = nmFindFieldDef(pMsgDef, byFId)) == NULL )
2086  {
2087  pCtl->m_bNoExec = true;
2088  pVal = NULL;
2089  NMLIB_WARNING("Unknown fid=%u @byte=%d - ignoring.", (uint_t)byFId, n);
2090  }
2091  else if( pFieldDef->m_eFType != (NMFType_T)byFType )
2092  {
2094  "Field definition ftype='%c'(0x%02x) != receive ftype='%c'(0x%02x).",
2095  NMLIB_ASCII_FTYPE(pFieldDef->m_eFType), pFieldDef->m_eFType,
2096  NMLIB_ASCII_FTYPE(byFType), byFType);
2097  }
2098 
2099  pVal = pStruct + pFieldDef->m_uOffset;
2100  }
2101 
2102  fnUnpack = nmLookupITVUnpacker(byFType);
2103 
2104  if( fnUnpack == NULL )
2105  {
2107  "ftype='%c'(0x%02x).",
2108  NMLIB_ASCII_FTYPE(pFieldDef->m_eFType), pFieldDef->m_eFType);
2109  }
2110 
2111  k = fnUnpack(pFieldDef, &buf[n], uMsgLen-(size_t)n, pVal, eEndian, pCtl);
2112 
2113  if( k < 0 )
2114  {
2115  return k;
2116  }
2117 
2118  n += k;
2119 
2120  pCtl->m_bNoExec = bNoExec;
2121 
2122  uCount--;
2123  }
2124 
2125  if( uCount > 0 )
2126  {
2128  "%s(%u): %u field(s) left unparsed - no more message",
2129  pMsgDef->m_sMsgName, pMsgDef->m_eMsgId, uCount);
2130  }
2131 
2132  return n;
2133 }
#define NM_ECODE_FTYPE
unknown field type
Definition: netmsgs.h:76
#define NMITV_FID_SIZE
1 byte field id size
Definition: netmsgs.h:217
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
uint_t m_eMsgId
message id (globally unique)
Definition: netmsgs.h:407
int(* NMUnpackFunc_T)(const NMFieldDef_T *, byte_t[], size_t, void *, NMEndian_T, NMCtl_T *)
#define NM_ECODE_EMSG
bad message
Definition: netmsgs.h:77
static NMUnpackFunc_T nmLookupITVUnpacker(NMFType_T eFType)
Lookup ITV unpacker function, given the message field type.
#define NMLIB_RAISE_ERROR(ecode, fmt,...)
Raise libnetmsgs error (i.e. return from calling function).
translated pad type for packed stream
Definition: netmsgs.h:113
#define NMLIB_WARNING(fmt,...)
Log libnetmsgs warning.
Definition: nmLibInternal.h:80
const NMFieldDef_T * nmFindFieldDef(const NMMsgDef_T *pMsgDef, byte_t byFId)
Find the field definition in the message definition, given the field id.
Definition: nmLibUtils.c:235
byte_t m_bNoExec
do [not] execute assignment of value
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
NMFType_T
Definition: netmsgs.h:110
const char * m_sMsgName
message/struct string name
Definition: netmsgs.h:406
pad internal field type
Definition: netmsgs.h:145
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NMITV_FHDR_SIZE_BASE
Definition: netmsgs.h:225
#define NMLIB_ASCII_FTYPE(ftype)
Printable ASCII Field Type.
size_t m_uOffset
member offset in assoc msg structure
Definition: netmsgs.h:384
static int nmUnpackITVString ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack variable length string ITV field from the message buffer.

Note
The null character is appended to the end of the unpacked value.
Parameters
pFieldDefPointer to message field definition.
[in]bufInput message buffer.
bufSizeSize of input buffer.
[out]pValPointer to value to unpack (set).
eEndianUnpacking order. See NMEndian_T.
pCtlInternal control.
Returns
On success, returns the number of bytes unpacked. On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 1821 of file nmLibPackITV.c.

References NMFieldThis_T::m_string, _nm_field_def_struct::m_this, NMFieldThisString_T::m_uMaxCount, NM_ECODE_NOMEM, NM_ECODE_RANGE, NMITV_FHDR_SIZE_STRING, NMLIB_RAISE_FIELD_ERROR, and NMLIB_TRACE_FIELD.

1827 {
1828  size_t uCount;
1829  size_t uMaxCount;
1830  size_t uFSize;
1831  char *sVal;
1832  int n;
1833 
1835 
1836  if( n > bufSize )
1837  {
1839  "buf_size=%zu, fhdr_size=%u", bufSize, n);
1840  }
1841 
1842  // string subheader
1843  uCount = (size_t)buf[2];
1844 
1845  // field definition and derived values
1846  uMaxCount = pFieldDef->m_this.m_string.m_uMaxCount;
1847  uFSize = (size_t)n + uCount;
1848  sVal = (char *)pVal;
1849 
1850  // exceeds maximum string length (sans null)
1851  if( uCount > uMaxCount )
1852  {
1854  "string_count=%zu > max_count=%zu.", uCount, uMaxCount);
1855  }
1856 
1857  // not enough space in buffer for string
1858  else if( uFSize > bufSize )
1859  {
1861  "buf_size=%zu < fsize=%zu", bufSize, uFSize);
1862  }
1863 
1864  // success
1865  else
1866  {
1867  memcpy(sVal, buf+n, uCount);
1868  sVal[uCount] = 0;
1869 
1870  NMLIB_TRACE_FIELD(pFieldDef, buf, uFSize, pCtl, "'%s'", sVal);
1871 
1872  return (int)uFSize;
1873  }
1874 }
#define NMITV_FHDR_SIZE_STRING
Definition: netmsgs.h:231
NMFieldThisString_T m_string
string field specific info
Definition: netmsgs.h:371
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
size_t m_uMaxCount
maximum number of characters sans null char
Definition: netmsgs.h:339
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NM_ECODE_RANGE
field size or value out-of-range
Definition: netmsgs.h:75
static int nmUnpackITVStruct ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack structure ITV field from the message buffer.

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

Definition at line 1883 of file nmLibPackITV.c.

References _nm_msg_def_struct::m_sMsgName, NMFieldThis_T::m_struct, _nm_field_def_struct::m_this, NMCtl_T::m_uDepth, NM_ECODE_NOMEM, NMITV_FHDR_SIZE_STRUCT, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, and nmUnpackITVStream().

1889 {
1890  const NMMsgDef_T *pStructDef; // structure definition
1891  size_t uCount; // struct field count
1892  int n; // byte count/error code
1893  int k; // subbyte count/error code
1894 
1896 
1897  if( n > bufSize )
1898  {
1900  "buf_size=%zu, fhdr_size=%u", bufSize, n);
1901  }
1902 
1903  // number of fields in struct
1904  uCount = (size_t)buf[2]; // fix
1905 
1906  pStructDef = pFieldDef->m_this.m_struct;
1907 
1908  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "structdef %s, member_count=%u",
1909  pStructDef->m_sMsgName, buf[2]); //pStructDef->m_uCount);
1910 
1911  pCtl->m_uDepth++;
1912 
1913  // copy struct field value
1914  k = nmUnpackITVStream(pStructDef, &buf[n], bufSize-(size_t)n, uCount,
1915  pVal, eEndian, pCtl);
1916 
1917  pCtl->m_uDepth--;
1918 
1919  return k>=0? n+k: k;
1920 }
byte_t m_uDepth
structured message depth
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
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.
NMFieldThisStruct_T m_struct
struct field specific info
Definition: netmsgs.h:372
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define NMITV_FHDR_SIZE_STRUCT
Definition: netmsgs.h:234
#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 NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVU16 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack an unsigned 16-bit ITV field from the message buffer.

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

Definition at line 1316 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_U16, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackU16().

1322 {
1323  int n; // byte count/error code
1324  int k; // subbyte count/error code
1325 
1326  // header size
1327  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1328 
1329  // not enough input buffer for header
1330  if( n > bufSize )
1331  {
1333  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1334  }
1335 
1336  // ignore this field
1337  else if( pCtl->m_bNoExec )
1338  {
1339  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_U16,
1340  pCtl);
1341  }
1342 
1343  // try to unpack value
1344  else if( (k = nmUnpackU16(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1345  {
1346  return k;
1347  }
1348 
1349  // success
1350  else
1351  {
1352  n += k;
1353 
1354  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hu", *((ushort_t *)pVal));
1355 
1356  return n;
1357  }
1358 }
byte_t m_bNoHdr
do [not] include field header in byte stream
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 NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMFVAL_LEN_U16
unsigned 16-bit field value length
Definition: netmsgs.h:175
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVU32 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack an unsigned 32-bit ITV field from the message buffer.

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

Definition at line 1416 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_U32, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackU32().

1422 {
1423  int n; // byte count/error code
1424  int k; // subbyte count/error code
1425 
1426  // header size
1427  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1428 
1429  // not enough input buffer for header
1430  if( n > bufSize )
1431  {
1433  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1434  }
1435 
1436  // ignore this field
1437  else if( pCtl->m_bNoExec )
1438  {
1439  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_U32,
1440  pCtl);
1441  }
1442 
1443  // try to unpack value
1444  else if( (k = nmUnpackU32(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1445  {
1446  return k;
1447  }
1448 
1449  // success
1450  else
1451  {
1452  n += k;
1453 
1454  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%u", *((uint_t *)pVal));
1455 
1456  return n;
1457  }
1458 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMFVAL_LEN_U32
unsigned 32-bit field value length
Definition: netmsgs.h:177
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
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVU64 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack an unsigned 64-bit ITV field from the message buffer.

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

Definition at line 1516 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_U64, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackU64().

1522 {
1523  int n; // byte count/error code
1524  int k; // subbyte count/error code
1525 
1526  // header size
1527  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1528 
1529  // not enough input buffer for header
1530  if( n > bufSize )
1531  {
1533  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1534  }
1535 
1536  // ignore this field
1537  else if( pCtl->m_bNoExec )
1538  {
1539  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_U64,
1540  pCtl);
1541  }
1542 
1543  // try to unpack value
1544  else if( (k = nmUnpackU64(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1545  {
1546  return k;
1547  }
1548 
1549  // success
1550  else
1551  {
1552  n += k;
1553 
1554  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%llu",
1555  *((ulonglong_t *)pVal));
1556 
1557  return n;
1558  }
1559 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMFVAL_LEN_U64
unsigned 64-bit field value length
Definition: netmsgs.h:179
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
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
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
static int nmUnpackITVU8 ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack an unsigned 8-bit ITV field from the message buffer.

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

Definition at line 1215 of file nmLibPackITV.c.

References NMCtl_T::m_bNoExec, NMCtl_T::m_bNoHdr, NM_ECODE_NOMEM, NMFVAL_LEN_U8, NMITV_FHDR_SIZE_SIMPLE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, nmUnpackITVNoExec(), and nmUnpackU8().

1221 {
1222  int n; // byte count/error code
1223  int k; // subbyte count/error code
1224 
1225  // header size
1226  n = pCtl->m_bNoHdr? 0: NMITV_FHDR_SIZE_SIMPLE;
1227 
1228  // not enough input buffer for header
1229  if( n > bufSize )
1230  {
1232  "buf_size=%zu < fhdr_size=%u", bufSize, n);
1233  }
1234 
1235  // ignore this field
1236  else if( pCtl->m_bNoExec )
1237  {
1238  return nmUnpackITVNoExec(pFieldDef, buf, bufSize, (size_t)n+NMFVAL_LEN_U8,
1239  pCtl);
1240  }
1241 
1242  // try to unpack value
1243  else if( (k = nmUnpackU8(&buf[n], bufSize-(size_t)n, pVal, eEndian)) < 0 )
1244  {
1245  return k;
1246  }
1247 
1248  // success
1249  else
1250  {
1251  n += k;
1252 
1253  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl, "%hhu", *((byte_t *)pVal));
1254 
1255  return n;
1256  }
1257 }
byte_t m_bNoHdr
do [not] include field header in byte stream
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
static int nmUnpackITVNoExec(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, size_t uFLen, NMCtl_T *pCtl)
Move parse cursor position past current field in message stream field.
byte_t m_bNoExec
do [not] execute assignment of value
#define NMITV_FHDR_SIZE_SIMPLE
Definition: netmsgs.h:228
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NMFVAL_LEN_U8
unsigned 8-bit field value length
Definition: netmsgs.h:172
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
static int nmUnpackITVVector ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  bufSize,
void *  pVal,
NMEndian_T  eEndian,
NMCtl_T pCtl 
)
static

Unpack variable length vector ITV field from the message buffer.

A vector is a one-dimension array of the given type.

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

Definition at line 1930 of file nmLibPackITV.c.

References NMCtl_T::m_bNoHdr, NMVec_T::m_buf, _nm_field_def_struct::m_eFType, NMFieldThisVector_T::m_pThisElem, _nm_field_def_struct::m_this, NMVec_T::m_uCount, NMCtl_T::m_uDepth, NMFieldThisVector_T::m_uElemSize, NMFieldThisVector_T::m_uMaxCount, NMFieldThis_T::m_vector, NM_ECODE_EMSG, NM_ECODE_FTYPE, NM_ECODE_NOMEM, NM_ECODE_RANGE, NMFTYPE_IS_SIMPLE, NMITV_FHDR_SIZE_VECTOR, NMLIB_ASCII_FTYPE, NMLIB_RAISE_FIELD_ERROR, NMLIB_TRACE_FIELD, and nmLookupITVUnpacker().

1936 {
1937  size_t uCount;
1938  byte_t byElemFType;
1939  size_t uMaxCount;
1940  size_t uElemSize;
1941  const NMFieldDef_T *pElemDef;
1942  NMVec_T *pVec;
1943  void *pItem;
1944  NMUnpackFunc_T fnUnpack = NULL;
1945  int n = NMITV_FHDR_SIZE_VECTOR;
1946  int k;
1947  size_t i;
1948 
1950 
1951  if( n > bufSize )
1952  {
1954  "buf_size=%zu, fhdr_size=%u", bufSize, n);
1955  }
1956 
1957  // vector subheader
1958  uCount = (size_t)buf[2];
1959  byElemFType = (byte_t)buf[3];
1960 
1961  // field definition and derived values
1962  uMaxCount = pFieldDef->m_this.m_vector.m_uMaxCount;
1963  uElemSize = pFieldDef->m_this.m_vector.m_uElemSize;
1964  pElemDef = pFieldDef->m_this.m_vector.m_pThisElem;
1965  pVec = (NMVec_T *)pVal; // generalized vector overlay
1966  pItem = (byte_t *)(pVec) + memberoffset(NMVec_T, u.m_buf);
1967  fnUnpack = nmLookupITVUnpacker(pElemDef->m_eFType);
1968 
1969  // received vector type mismatch with definition
1970  if( byElemFType != (byte_t)pElemDef->m_eFType )
1971  {
1973  "vector_elem_ftype='%c'(0x%02x) != rcv'd ftype='%c'(0x%02x).",
1974  NMLIB_ASCII_FTYPE(pElemDef->m_eFType), pElemDef->m_eFType,
1975  NMLIB_ASCII_FTYPE(byElemFType), byElemFType);
1976  }
1977 
1978  // exceeds maximum
1979  else if( uCount > uMaxCount )
1980  {
1982  "vector_count=%zu > max_count=%zu.", uCount, uMaxCount);
1983  }
1984 
1985  // no unpacker
1986  else if( fnUnpack == NULL )
1987  {
1989  "vector_elem_ftype='%c'(0x%02x).",
1990  NMLIB_ASCII_FTYPE(pElemDef->m_eFType), pElemDef->m_eFType);
1991  }
1992 
1993  NMLIB_TRACE_FIELD(pFieldDef, buf, n, pCtl,
1994  "vector_count=%zu, vector_elem_ftype='%c'(0x%02x)",
1995  uCount, NMLIB_ASCII_FTYPE(byElemFType), byElemFType);
1996 
1997  // no header for simple vector element types
1998  if( NMFTYPE_IS_SIMPLE(pElemDef->m_eFType) )
1999  {
2000  pCtl->m_bNoHdr = true;
2001  }
2002 
2003  pCtl->m_uDepth++;
2004 
2005  // unpack field into vector field
2006  for(i=0; i<uCount; ++i)
2007  {
2008  k = fnUnpack(pElemDef, &buf[n], bufSize-(size_t)n, pItem, eEndian, pCtl);
2009 
2010  if( k < 0 )
2011  {
2012  return k;
2013  }
2014 
2015  n += k;
2016 
2017  pItem += uElemSize;
2018  }
2019 
2020  pCtl->m_uDepth--;
2021  pCtl->m_bNoHdr = false;
2022 
2023  // actual number of vector items
2024  pVec->m_uCount = n>0? uCount: 0;
2025 
2026  return n;
2027 }
byte_t m_bNoHdr
do [not] include field header in byte stream
byte_t m_uDepth
structured message depth
size_t m_uMaxCount
maximum number of vector elements
Definition: netmsgs.h:354
NMFieldThisVector_T m_vector
vector field specific info
Definition: netmsgs.h:373
#define NM_ECODE_FTYPE
unknown field type
Definition: netmsgs.h:76
#define NMLIB_TRACE_FIELD(p, buf, n, ctl, fmt,...)
Trace field.
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
int(* NMUnpackFunc_T)(const NMFieldDef_T *, byte_t[], size_t, void *, NMEndian_T, NMCtl_T *)
#define NM_ECODE_EMSG
bad message
Definition: netmsgs.h:77
static NMUnpackFunc_T nmLookupITVUnpacker(NMFType_T eFType)
Lookup ITV unpacker function, given the message field type.
#define NMFTYPE_IS_SIMPLE(ft)
Returns true if field type is a simple type.
Definition: netmsgs.h:164
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define NMITV_FHDR_SIZE_VECTOR
Definition: netmsgs.h:237
#define NM_ECODE_NOMEM
not enough buffer memory available
Definition: netmsgs.h:73
NMFieldDef_P m_pThisElem
vector element specific info
Definition: netmsgs.h:356
size_t m_uElemSize
vector element storage size
Definition: netmsgs.h:355
size_t m_uCount
number of items in vector
Definition: netmsgs.h:393
#define NMLIB_RAISE_FIELD_ERROR(ecode, p, fmt,...)
Raise libnetmsgs field error (i.e. return from calling function).
#define NMLIB_ASCII_FTYPE(ftype)
Printable ASCII Field Type.
#define NM_ECODE_RANGE
field size or value out-of-range
Definition: netmsgs.h:75
byte_t * m_buf
the vector
Definition: netmsgs.h:397

Variable Documentation

NMLookupTblEntry_T NMITVLookupTbl[]
static
Initial value:
=
{
{NMFTypeChar, nmPackITVU8, nmUnpackITVU8},
}
static int nmUnpackITVP32(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a 32-bit pointer ITV field from the message buffer.
64-bit IEEE 754 FPN double
Definition: netmsgs.h:120
unsigned 8-bit integer unsigned char
Definition: netmsgs.h:118
static int nmPackITVU16(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack an unsigned 16-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:391
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
static int nmUnpackITVStruct(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack structure ITV field from the message buffer.
static int nmPackITVS64(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a signed 64-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:621
static int nmUnpackITVU32(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an unsigned 32-bit ITV field from the message buffer.
static int nmUnpackITVS64(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a signed 64-bit ITV field from the message buffer.
static int nmUnpackITVU16(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an unsigned 16-bit ITV field from the message buffer.
signed 32-bit integer int
Definition: netmsgs.h:138
string char[]
Definition: netmsgs.h:144
static int nmPackITVS16(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a signed 16-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:437
static int nmPackITVP32(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a 32-bit pointer ITV field into the message buffer.
Definition: nmLibPackITV.c:759
static int nmPackITVPad(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack pad bytes into the message buffer.
Definition: nmLibPackITV.c:226
static int nmUnpackITVString(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack variable length string ITV field from the message buffer.
8-bit ASCII characters char
Definition: netmsgs.h:133
static int nmPackITVS8(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a signed 8-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:345
signed 64-bit integer long long
Definition: netmsgs.h:142
static int nmPackITVU32(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack an unsigned 32-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:483
8-bit bool 0/1 bool_t
Definition: netmsgs.h:117
static int nmUnpackITVU8(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an unsigned 8-bit ITV field from the message buffer.
static int nmUnpackITVPad(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack pad byte from the message buffer.
static int nmPackITVU8(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack an unsigned 8-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:299
static int nmUnpackITVS16(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a signed 16-bit ITV field from the message buffer.
32-bit pointer (overloaded) void*
Definition: netmsgs.h:140
static int nmPackITVP64(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a 64-bit pointer ITV field into the message buffer.
Definition: nmLibPackITV.c:798
static int nmPackITVU64(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack an unsigned 64-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:575
static int nmPackITVString(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack null-terminated, variable length string ITV field into the message buffer.
Definition: nmLibPackITV.c:840
static int nmUnpackITVU64(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an unsigned 64-bit ITV field from the message buffer.
static int nmUnpackITVF32(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a 32-bit floating-point number ITV field from the message buffer.
64-bit pointer (overloaded) void*
Definition: netmsgs.h:126
static int nmPackITVF64(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a 64-bit floating-point number ITV field into the message buffer.
Definition: nmLibPackITV.c:713
static int nmPackITVVector(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack variable length vector ITV field into the message buffer.
Definition: nmLibPackITV.c:944
signed 8-bit integer signed char
Definition: netmsgs.h:131
one dimensional array VType[]
Definition: netmsgs.h:130
static int nmPackITVS32(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a signed 32-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:529
static int nmUnpackITVF64(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a 64-bit floating-point number ITV field from the message buffer.
static int nmUnpackITVS32(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a signed 32-bit ITV field from the message buffer.
static int nmUnpackITVVector(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack variable length vector ITV field from the message buffer.
static int nmPackITVBool(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a boolean into an 8-bit ITV field into the message buffer.
Definition: nmLibPackITV.c:257
unsigned 32-bit integer unsigned int
Definition: netmsgs.h:124
pad internal field type
Definition: netmsgs.h:145
static int nmPackITVF32(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a 32-bit floating-point number ITV field into the message buffer.
Definition: nmLibPackITV.c:667
static int nmUnpackITVBool(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack an unsigned 8-bit boolean ITV field from the message buffer.
static int nmUnpackITVP64(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a 64-bit pointer ITV field from the message buffer.
static int nmPackITVStruct(const NMFieldDef_T *pFieldDef, void *pVal, byte_t buf[], size_t bufSize, NMEndian_T eEndian, NMCtl_T *pCtl)
Pack a structure ITV field into the message buffer.
Definition: nmLibPackITV.c:903
static int nmUnpackITVS8(const NMFieldDef_T *pFieldDef, byte_t buf[], size_t bufSize, void *pVal, NMEndian_T eEndian, NMCtl_T *pCtl)
Unpack a signed 8-bit ITV field from the message buffer.
unsigned 16-bit integer unsigned short
Definition: netmsgs.h:122
signed 16-bit integer short
Definition: netmsgs.h:136

ITV Info Lookup Table

Warning
Keep in asending order by ftype.

Definition at line 2145 of file nmLibPackITV.c.