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

Internal intra-library definitions. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.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 _NMSET_VAL(_this, pv, T)   (T)(_this.m_bits & NMBITS_HAS_CONST? (T)(_this.m_valConst): *((T*)pv))
 Set field value. More...
 
#define _NMCHK_MIN(fname, _this, v, T, fmt)
 Check value is ≥ minimum. More...
 
#define _NMCHK_MAX(fname, _this, v, T, fmt)
 Check value is ≤ maximum. More...
 

Functions

int nmSetU8 (const NMFieldDef_T *pFieldDef, void *pValIn, byte_t *pValOut)
 Helper function to set an unsigned 8-bit integer. More...
 
int nmSetS8 (const NMFieldDef_T *pFieldDef, void *pValIn, signed char *pValOut)
 Helper function to set a signed 8-bit integer. More...
 
int nmSetU16 (const NMFieldDef_T *pFieldDef, void *pValIn, ushort_t *pValOut)
 Helper function to set an unsigned 16-bit integer. More...
 
int nmSetS16 (const NMFieldDef_T *pFieldDef, void *pValIn, short *pValOut)
 Helper function to set a signed 16-bit integer. More...
 
int nmSetU32 (const NMFieldDef_T *pFieldDef, void *pValIn, uint_t *pValOut)
 Helper function to set an unsigned 32-bit integer. More...
 
int nmSetS32 (const NMFieldDef_T *pFieldDef, void *pValIn, int *pValOut)
 Helper function to set a signed 32-bit integer. More...
 
int nmSetU64 (const NMFieldDef_T *pFieldDef, void *pValIn, ulonglong_t *pValOut)
 Helper function to set an unsigned 64-bit integer. More...
 
int nmSetS64 (const NMFieldDef_T *pFieldDef, void *pValIn, long long *pValOut)
 Helper function to set a signed 64-bit integer. More...
 
int nmSetF32 (const NMFieldDef_T *pFieldDef, void *pValIn, float *pValOut)
 Helper function to set a 32-bit floating point number. More...
 
int nmSetF64 (const NMFieldDef_T *pFieldDef, void *pValIn, double *pValOut)
 Helper function to set a 64-bit floating point number. More...
 
void nmTraceField (const NMFieldDef_T *pFieldDef, byte_t buf[], size_t uCount, uint_t uDepth, const char *sFmt,...)
 Trace packing/unpacking of a message field. More...
 

Variables

const int NMHashOffset = (int)NMFTypeBool
 hash base offset
 
const int NMHashNoIdx = 0xff
 hash no index value
 
const byte_t NMHashTbl []
 
const size_t NMHashNumEntries = arraysize(NMHashTbl)
 

Detailed Description

Internal intra-library definitions.

LastChangedDate
2010-02-12 14:27:57 -0700 (Fri, 12 Feb 2010)
Rev
247
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 nmLibInternal.c.

Macro Definition Documentation

#define _NMCHK_MAX (   fname,
  _this,
  v,
  T,
  fmt 
)
Value:
do \
{ \
if( _this.m_bits & NMBITS_HAS_MAX ) \
{ \
if( (v) > (T)(_this.m_valMax) ) \
{ \
NMLIB_RAISE_ERROR(NM_ECODE_RANGE, "%s val=" fmt " > max=" fmt, \
fname, v, (T)(_this.m_valMax)); \
} \
} \
} while(0)
#define NMLIB_RAISE_ERROR(ecode, fmt,...)
Raise libnetmsgs error (i.e. return from calling function).
#define NMBITS_HAS_MAX
field has a maximum value
Definition: netmsgs.h:257
#define NM_ECODE_RANGE
field size or value out-of-range
Definition: netmsgs.h:75

Check value is ≤ maximum.

Note
Out-of-range violation results is calling function return.
Parameters
fnameThis field's string name.
_thisThis field's specific information.
vField value.
TField C type.
fmtFormat string on error.

Definition at line 112 of file nmLibInternal.c.

Referenced by nmSetF32(), nmSetF64(), nmSetS16(), nmSetS32(), nmSetS64(), nmSetS8(), nmSetU16(), nmSetU32(), nmSetU64(), and nmSetU8().

#define _NMCHK_MIN (   fname,
  _this,
  v,
  T,
  fmt 
)
Value:
do \
{ \
if( _this.m_bits & NMBITS_HAS_MIN ) \
{ \
if( (v) < (T)(_this.m_valMin) ) \
{ \
NMLIB_RAISE_ERROR(NM_ECODE_RANGE, "%s val=" fmt " < min=" fmt, \
fname, v, (T)(_this.m_valMin)); \
} \
} \
} while(0)
#define NMLIB_RAISE_ERROR(ecode, fmt,...)
Raise libnetmsgs error (i.e. return from calling function).
#define NM_ECODE_RANGE
field size or value out-of-range
Definition: netmsgs.h:75
#define NMBITS_HAS_MIN
field has a minimum value
Definition: netmsgs.h:256

Check value is ≥ minimum.

Note
Out-of-range violation results is calling function return.
Parameters
fnameThis field's string name.
_thisThis field's specific information.
vField value.
TField C type.
fmtFormat string on error.

Definition at line 88 of file nmLibInternal.c.

Referenced by nmSetF32(), nmSetF64(), nmSetS16(), nmSetS32(), nmSetS64(), nmSetS8(), nmSetU16(), nmSetU32(), nmSetU64(), and nmSetU8().

#define _NMSET_VAL (   _this,
  pv,
 
)    (T)(_this.m_bits & NMBITS_HAS_CONST? (T)(_this.m_valConst): *((T*)pv))

Set field value.

Parameters
_thisThis field's specific information.
pvPointer to field value.
TField C type.

Definition at line 74 of file nmLibInternal.c.

Referenced by nmSetF32(), nmSetF64(), nmSetS16(), nmSetS32(), nmSetS64(), nmSetS8(), nmSetU16(), nmSetU32(), nmSetU64(), and nmSetU8().

Function Documentation

int nmSetF32 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
float *  pValOut 
)

Helper function to set a 32-bit floating point number.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 443 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, NMFieldThis_T::m_f32, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, and NM_OK.

Referenced by nmPackFlatF32(), and nmPackITVF32().

444 {
445  float val;
446 
447  // set value, override if constant value
448  val = _NMSET_VAL(pFieldDef->m_this.m_f32, pValIn, float);
449 
450  // check against minimum limits
451  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_f32, val, float, "%f");
452 
453  // check against maximum limits
454  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_f32, val, float, "%f");
455 
456  // set
457  *pValOut = val;
458 
459  return NM_OK;
460 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
NMFieldThisF32_T m_f32
32-bit fpn specific info
Definition: netmsgs.h:369
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
int nmSetF64 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
double *  pValOut 
)

Helper function to set a 64-bit floating point number.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 474 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, NMFieldThis_T::m_f64, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, and NM_OK.

Referenced by nmPackFlatF64(), and nmPackITVF64().

475 {
476  double val;
477 
478  // set value, override if constant value
479  val = _NMSET_VAL(pFieldDef->m_this.m_f64, pValIn, double);
480 
481  // check against minimum limits
482  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_f64, val, double, "%f");
483 
484  // check against maximum limits
485  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_f64, val, double, "%f");
486 
487  // set
488  *pValOut = val;
489 
490  return NM_OK;
491 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
NMFieldThisF64_T m_f64
64-bit fpn specific info
Definition: netmsgs.h:370
int nmSetS16 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
short *  pValOut 
)

Helper function to set a signed 16-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 282 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u16, and NM_OK.

Referenced by nmPackFlatS16(), and nmPackITVS16().

283 {
284  short val;
285 
286  // set value, override if is constant value
287  val = _NMSET_VAL(pFieldDef->m_this.m_u16, pValIn, short);
288 
289  // check against minimum limits
290  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u16, val, short, "%hd");
291 
292  // check against maximum limits
293  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u16, val, short, "%hd");
294 
295  // set
296  *pValOut = val;
297 
298  return NM_OK;
299 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
NMFieldThisU16_T m_u16
[unsigned] 16-bit integer specific info
Definition: netmsgs.h:366
int nmSetS32 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
int *  pValOut 
)

Helper function to set a signed 32-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 344 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u32, and NM_OK.

Referenced by nmPackFlatS32(), and nmPackITVS32().

345 {
346  int val;
347 
348  // set value, override if constant value
349  val = _NMSET_VAL(pFieldDef->m_this.m_u32, pValIn, int);
350 
351  // check against minimum limits
352  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u32, val, int, "%d");
353 
354  // check against maximum limits
355  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u32, val, int, "%d");
356 
357  // set
358  *pValOut = val;
359 
360  return NM_OK;
361 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
NMFieldThisU32_T m_u32
[unsigned] 32-bit integer specific info
Definition: netmsgs.h:367
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
int nmSetS64 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
long long *  pValOut 
)

Helper function to set a signed 64-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 410 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u64, and NM_OK.

Referenced by nmPackFlatS64(), and nmPackITVS64().

411 {
412  long long val;
413 
414  // set value, override if constant value
415  val = _NMSET_VAL(pFieldDef->m_this.m_u64, pValIn, long long);
416 
417  // check against minimum limits
418  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u64,
419  val, long long, "%hhu");
420 
421  // check against maximum limits
422  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u64,
423  val, long long, "%hhu");
424 
425  // set
426  *pValOut = val;
427 
428  return NM_OK;
429 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
NMFieldThisU64_T m_u64
[unsigned] 64-bit integer specific info
Definition: netmsgs.h:368
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
int nmSetS8 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
signed char *  pValOut 
)

Helper function to set a signed 8-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 216 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u8, and NM_OK.

Referenced by nmPackFlatS8(), and nmPackITVS8().

217 {
218  signed char val;
219 
220  // set value, override if is constant value
221  val = _NMSET_VAL(pFieldDef->m_this.m_u8, pValIn, signed char);
222 
223  // check against minimum limits
224  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u8,
225  val, signed char, "%hhd");
226 
227  // check against maximum limits
228  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u8,
229  val, signed char, "%hhd");
230 
231  // set
232  *pValOut = val;
233 
234  return NM_OK;
235 }
NMFieldThisU8_T m_u8
[unsigned] 8-bit integer specific info
Definition: netmsgs.h:365
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
int nmSetU16 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
ushort_t *  pValOut 
)

Helper function to set an unsigned 16-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 249 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u16, and NM_OK.

Referenced by nmPackFlatU16(), and nmPackITVU16().

250 {
251  ushort_t val;
252 
253  // set value, override if is constant value
254  val = _NMSET_VAL(pFieldDef->m_this.m_u16, pValIn, ushort_t);
255 
256  // check against minimum limits
257  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u16,
258  val, ushort_t, "%hu");
259 
260  // check against maximum limits
261  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u16,
262  val, ushort_t, "%hu");
263 
264  // set
265  *pValOut = val;
266 
267  return NM_OK;
268 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
NMFieldThisU16_T m_u16
[unsigned] 16-bit integer specific info
Definition: netmsgs.h:366
int nmSetU32 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
uint_t *  pValOut 
)

Helper function to set an unsigned 32-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 313 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u32, and NM_OK.

Referenced by nmPackFlatU32(), and nmPackITVU32().

314 {
315  uint_t val;
316 
317  // set value, override if is constant value
318  val = _NMSET_VAL(pFieldDef->m_this.m_u32, pValIn, uint_t);
319 
320  // check against minimum limits
321  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u32, val, uint_t, "%u");
322 
323  // check against maximum limits
324  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u32, val, uint_t, "%u");
325 
326  // set
327  *pValOut = val;
328 
329  return NM_OK;
330 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
NMFieldThisU32_T m_u32
[unsigned] 32-bit integer specific info
Definition: netmsgs.h:367
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
int nmSetU64 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
ulonglong_t *  pValOut 
)

Helper function to set an unsigned 64-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 375 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u64, and NM_OK.

Referenced by nmPackFlatU64(), and nmPackITVU64().

378 {
379  ulonglong_t val;
380 
381  // set value, override if constant value
382  val = _NMSET_VAL(pFieldDef->m_this.m_u64, pValIn, ulonglong_t);
383 
384  // check against minimum limits
385  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u64,
386  val, ulonglong_t, "%llu");
387 
388  // check against maximum limits
389  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u64,
390  val, ulonglong_t, "%llu");
391 
392  // set
393  *pValOut = val;
394 
395  return NM_OK;
396 }
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
NMFieldThisU64_T m_u64
[unsigned] 64-bit integer specific info
Definition: netmsgs.h:368
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
int nmSetU8 ( const NMFieldDef_T pFieldDef,
void *  pValIn,
byte_t *  pValOut 
)

Helper function to set an unsigned 8-bit integer.

Parameters
pFieldDefPointer to message field definition.
[in]pValInPointer to field value.
[out]pValOutPointer to constrained, assigned field value.
Returns
On success, returns NM_OK.
On error, the appropriate negated netmsgs error code ( < 0) is returned.

Definition at line 182 of file nmLibInternal.c.

References _NMCHK_MAX, _NMCHK_MIN, _NMSET_VAL, _nm_field_def_struct::m_sFName, _nm_field_def_struct::m_this, NMFieldThis_T::m_u8, and NM_OK.

Referenced by nmPackFlatU8(), and nmPackITVU8().

183 {
184  byte_t val;
185 
186  // set value, override if is constant value
187  val = _NMSET_VAL(pFieldDef->m_this.m_u8, pValIn, byte_t);
188  //val = (pFieldDef->m_this.m_u8.m_bits & NMBITS_HAS_CONST?
189  // (byte_t)(pFieldDef->m_this.m_u8.m_valConst):
190  // *((byte_t*)pValIn))
191 
192  // check against minimum limits
193  _NMCHK_MIN(pFieldDef->m_sFName, pFieldDef->m_this.m_u8, val, byte_t, "%hhu");
194 
195  // check against maximum limits
196  _NMCHK_MAX(pFieldDef->m_sFName, pFieldDef->m_this.m_u8, val, byte_t, "%hhu");
197 
198  // set
199  *pValOut = val;
200 
201  return NM_OK;
202 }
NMFieldThisU8_T m_u8
[unsigned] 8-bit integer specific info
Definition: netmsgs.h:365
#define _NMSET_VAL(_this, pv, T)
Set field value.
Definition: nmLibInternal.c:74
#define NM_OK
not an error, success
Definition: netmsgs.h:70
NMFieldThis_T m_this
specific field information
Definition: netmsgs.h:385
#define _NMCHK_MAX(fname, _this, v, T, fmt)
Check value is &le; maximum.
const char * m_sFName
field string name
Definition: netmsgs.h:381
#define _NMCHK_MIN(fname, _this, v, T, fmt)
Check value is &ge; minimum.
Definition: nmLibInternal.c:88
void nmTraceField ( const NMFieldDef_T pFieldDef,
byte_t  buf[],
size_t  uCount,
uint_t  uDepth,
const char *  sFmt,
  ... 
)

Trace packing/unpacking of a message field.

Parameters
pFieldDefPointer to field definition.
bufPacked/unpacked buffer.
uCountNumber of bytes in buffer to trace.
uDepthDepth of field in recursive definition.
sFmtField representation format string.
...Field representation variable arguments.

Definition at line 504 of file nmLibInternal.c.

References _nm_field_def_struct::m_eFId, _nm_field_def_struct::m_eFType, _nm_field_def_struct::m_sFName, NMFID_NONE, and nmPrintBuf().

510 {
511  va_list ap;
512  char bufRepr[256];
513  uint_t uIndent;
514  int n;
515 
516  va_start(ap, sFmt);
517  vsnprintf(bufRepr, sizeof(bufRepr), sFmt, ap);
518  va_end(ap);
519  bufRepr[sizeof(bufRepr)-1] = 0;
520 
521  uIndent = uDepth * 2;
522 
523  if( pFieldDef != NULL )
524  {
525  // "normal"
526  if( pFieldDef->m_eFId != NMFID_NONE )
527  {
528  n = fprintf(stderr, "%*s%c:%s(%u) = %s: ",
529  uIndent, "", pFieldDef->m_eFType, pFieldDef->m_sFName,
530  pFieldDef->m_eFId, bufRepr);
531  }
532  // vector items have no field ids
533  else
534  {
535  n = fprintf(stderr, "%*s[%c]: = %s: ",
536  uIndent, "", pFieldDef->m_eFType, bufRepr);
537  }
538  }
539  else
540  {
541  n = fprintf(stderr, "%*s%s: ", uDepth*2, "", bufRepr);
542  }
543 
544  if( uCount > 0 )
545  {
546  if( n > 36 )
547  {
548  fprintf(stderr, "\n");
549  n = 0;
550  }
551 
552  fprintf(stderr, "%*s", 38-n, "");
553  nmPrintBuf(stderr, NULL, buf, uCount, 8, 38);
554  }
555  fprintf(stderr, "\n");
556 }
NMFType_T m_eFType
field type
Definition: netmsgs.h:383
#define NMFID_NONE
no field id (reserved)
Definition: netmsgs.h:211
const char * m_sFName
field string name
Definition: netmsgs.h:381
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
uint_t m_eFId
filed id (message/struct unique)
Definition: netmsgs.h:382

Variable Documentation

const size_t NMHashNumEntries = arraysize(NMHashTbl)

number of hash entries

Definition at line 168 of file nmLibInternal.c.

Referenced by NMHashFType().

const byte_t NMHashTbl[]
Initial value:
=
{
0, 0xff, 0xff, 1, 0xff, 0xff, 0xff, 2,
0xff, 3, 4, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 5, 6, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 7, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 8, 9, 0xff, 0xff, 10,
0xff, 11, 12, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 13, 14, 0xff, 15, 0xff, 0xff, 0xff,
0xff, 16, 0xff, 0xff, 17
}

Field Type Hash Table.

Maps field type to zero base index.

Note
The table is hand-crafted to optimize access speed.

Definition at line 140 of file nmLibInternal.c.

Referenced by NMHashFType().