botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
bsNullMsgs.c
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: bsNullMsgs.c
4 //
5 /*!
6  * \file
7  *
8  * \brief BotSense bsProxy server - client /dev/null NetMsgs XML Definition
9  *
10  * \warning This file was auto-generated on 2018.08.10 13:54:23 from the NetMsgs
11  * XML specification bsNullMsgs.xml.
12  *
13  * \par Copyright:
14  * (C) 2018. RoadNarrows LLC
15  * (http://www.roadnarrows.com)
16  * All Rights Reserved
17  */
18 ///////////////////////////////////////////////////////////////////////////////
19 
20 
21 #include "rnr/rnrconfig.h"
22 #include "rnr/log.h"
23 #include "rnr/netmsgs.h"
24 
25 #include "botsense/bsNullMsgs.h"
26 
27 #ifndef EOFDEF
28 /*! End of Field Definition entry. */
29 #define EOFDEF {NULL, 0, NMFTypeNone, 0, }
30 #endif // EOFDEF
31 
32 
33 //-----------------------------------------------------------------------------
34 // Private Interface
35 //-----------------------------------------------------------------------------
36 
37 
38 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39 // Message BsNullReqWrite Definition
40 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41 
42 /*!
43  * BsNullReqWritewritebuf Field Definitions
44  */
45 static const NMFieldDef_T BsNullReqWritewritebufFieldDef[] =
46 {
47  {
48  .m_sFName = "writebuf",
49  .m_eFId = 0,
50  .m_eFType = NMFTypeU8,
51  .m_uOffset = (size_t)0,
52  .m_this.m_u8.m_bits = (byte_t)(0),
53  .m_this.m_u8.m_valMin = (byte_t)(0),
54  .m_this.m_u8.m_valMax = (byte_t)(0),
55  .m_this.m_u8.m_valConst = (byte_t)(0),
56  },
57  EOFDEF
58 };
59 
60 /*!
61  * BsNullReqWrite Field Id Enumeration
62  */
63 typedef enum
64 {
65  BsNullReqWriteFIdReserved = 0, ///< reserved field id
66  BsNullReqWriteFIdwritebuf = 1, ///< writebuf field id
67  BsNullReqWriteFIdNumOf = 2 ///< number of fields
69 
70 /*!
71  * BsNullReqWrite Field Definitions
72  */
73 static const NMFieldDef_T BsNullReqWriteFieldDefs[] =
74 {
75  {
76  .m_sFName = "writebuf",
77  .m_eFId = BsNullReqWriteFIdwritebuf,
78  .m_eFType = NMFTypeVector,
79  .m_uOffset = memberoffset(BsNullReqWrite_T, m_writebuf),
80  .m_this.m_vector.m_uMaxCount
82  .m_this.m_vector.m_uElemSize
83  = sizeof(byte_t),
84  .m_this.m_vector.m_pThisElem
86  },
87  EOFDEF
88 };
89 
90 /*!
91  * BsNullReqWrite Message Definition
92  */
93 static const NMMsgDef_T BsNullReqWriteMsgDef =
94 {
95  .m_sMsgName = "BsNullReqWrite",
96  .m_eMsgId = BsNullMsgIdReqWrite,
97  .m_uCount = (size_t)(1),
98  .m_pFields = BsNullReqWriteFieldDefs
99 };
100 
101 
102 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103 // Message BsNullRspWrite Definition
104 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
105 
106 /*!
107  * BsNullRspWrite Field Id Enumeration
108  */
109 typedef enum
110 {
111  BsNullRspWriteFIdReserved = 0, ///< reserved field id
112  BsNullRspWriteFIdbyteswritten = 1, ///< byteswritten field id
113  BsNullRspWriteFIdNumOf = 2 ///< number of fields
115 
116 /*!
117  * BsNullRspWrite Field Definitions
118  */
119 static const NMFieldDef_T BsNullRspWriteFieldDefs[] =
120 {
121  {
122  .m_sFName = "byteswritten",
124  .m_eFType = NMFTypeU8,
125  .m_uOffset = memberoffset(BsNullRspWrite_T, m_byteswritten),
126  .m_this.m_u8.m_bits = (byte_t)(0),
127  .m_this.m_u8.m_valMin = (byte_t)(0),
128  .m_this.m_u8.m_valMax = (byte_t)(0),
129  .m_this.m_u8.m_valConst = (byte_t)(0),
130  },
131  EOFDEF
132 };
133 
134 /*!
135  * BsNullRspWrite Message Definition
136  */
137 static const NMMsgDef_T BsNullRspWriteMsgDef =
138 {
139  .m_sMsgName = "BsNullRspWrite",
140  .m_eMsgId = BsNullMsgIdRspWrite,
141  .m_uCount = (size_t)(1),
142  .m_pFields = BsNullRspWriteFieldDefs
143 };
144 
145 
146 //-----------------------------------------------------------------------------
147 // Public Interface
148 //-----------------------------------------------------------------------------
149 
150 /*!
151  * BsNull Message Definition Look-Up Table. Indexed by BsNullMsgId_T enum.
152  */
153 const NMMsgDef_T *BsNullMsgDefLookupTbl[] =
154 {
155  NULL, ///< [BsNullMsgIdNone]
156  &BsNullReqWriteMsgDef, ///< [BsNullMsgIdReqWrite]
157  &BsNullRspWriteMsgDef, ///< [BsNullMsgIdRspWrite]
158  NULL ///< [BsNullMsgIdNumOf]
159 };
160 
161 /*!
162  * BsNull Message Maximum Size Look-Up Table. Indexed by BsNullMsgId_T enum.
163  */
165 {
166  (size_t)(0), ///< [BsNullMsgIdNone]
167  (size_t)(262), ///< [BsNullMsgIdReqWrite]
168  (size_t)(6), ///< [BsNullMsgIdRspWrite]
169  (size_t)(0) ///< [BsNullMsgIdNumOf]
170 };
171 
172 
173 //-----------------------------------------------------------------------------
174 // Functions
175 //-----------------------------------------------------------------------------
176 
177 /*!
178  * \brief Look up the message definition associated with the message id.
179  *
180  * \param eMsgId Message Id.
181  *
182  * \return
183  * On success, returns the pointer to the NMMsgDef_T.
184  * On error, NULL is returned.
185  */
186 const NMMsgDef_T * BsNullLookupMsgDef( BsNullMsgId_T eMsgId )
187 {
188  if( (uint_t)eMsgId >= (uint_t)BsNullMsgIdNumOf )
189  {
190  return NULL;
191  }
192  else
193  {
194  return BsNullMsgDefLookupTbl[(uint_t)eMsgId];
195  }
196 }
197 
198 /*!
199  * \brief Look up the message maximum length associated with the message id.
200  *
201  * The maximum length is the total number of packed bytes possible for the
202  * given message. The message may be much shorter.
203  *
204  * \param eMsgId Message Id.
205  *
206  * \return
207  * On success, returns the number of bytes.
208  * On error, 0 is returned.
209  */
211 {
212  if( (uint_t)eMsgId >= (uint_t)BsNullMsgIdNumOf )
213  {
214  return (size_t)0;
215  }
216  else
217  {
218  return BsNullMsgMaxLenLookupTbl[(uint_t)eMsgId];
219  }
220 }
221 
222 /*!
223  * \brief Pack a ITV message in big-endian byte order.
224  *
225  * \param eMsgId Message Id.
226  * \param [in] pStruct Pointer to the associated, populated message
227  * structure.
228  * \param [out] buf Output message buffer.
229  * \param bufSize Size of output buffer.
230  * \param bTrace Do [not] trace packing.
231  *
232  * \return
233  * On success, returns the number of bytes packed.
234  * On error, returns the appropriate < 0 negated NM_ECODE.
235  */
237  void * pStruct,
238  byte_t buf[],
239  size_t bufSize,
240  bool_t bTrace )
241 {
242  const NMMsgDef_T *pMsgDef;
243 
244  if( (pMsgDef = BsNullLookupMsgDef(eMsgId)) == NULL )
245  {
246  LOGERROR("%s(ecode=%d): msgid=%u.",
247  nmStrError(NM_ECODE_MSGID), NM_ECODE_MSGID, eMsgId);
248  return -NM_ECODE_MSGID;
249  }
250 
251  if( bTrace )
252  {
253  return nmPackITVMsgDebug(pMsgDef, pStruct, buf, bufSize, NMEndianBig);
254  }
255  else
256  {
257  return nmPackITVMsg(pMsgDef, pStruct, buf, bufSize, NMEndianBig);
258  }
259 }
260 
261 /*!
262  * \brief Unpack a ITV message in big-endian byte order.
263  *
264  * \param eMsgId Message Id.
265  * \param [in] buf Input message buffer.
266  * \param uMsgLen Length of message (bytes) in input buffer.
267  * \param [out] pStruct Pointer to the associated message structure.
268  * \param bTrace Do [not] trace packing.
269  *
270  * \return
271  * On success, returns the number of bytes unpacked.
272  * On error, returns the appropriate < 0 negated NM_ECODE.
273  */
275  byte_t buf[],
276  size_t uMsgLen,
277  void * pStruct,
278  bool_t bTrace )
279 {
280  const NMMsgDef_T *pMsgDef;
281 
282  if( (pMsgDef = BsNullLookupMsgDef(eMsgId)) == NULL )
283  {
284  LOGERROR("%s(ecode=%d): msgid=%u.",
285  nmStrError(NM_ECODE_MSGID), NM_ECODE_MSGID, eMsgId);
286  return -NM_ECODE_MSGID;
287  }
288 
289  if( bTrace )
290  {
291  return nmUnpackITVMsgDebug(pMsgDef, buf, uMsgLen, pStruct, NMEndianBig);
292  }
293  else
294  {
295  return nmUnpackITVMsg(pMsgDef, buf, uMsgLen, pStruct, NMEndianBig);
296  }
297 }
298 
size_t BsNullLookupMsgMaxLen(BsNullMsgId_T eMsgId)
Look up the message maximum length associated with the message id.
Definition: bsNullMsgs.c:210
static const NMMsgDef_T BsNullReqWriteMsgDef
Definition: bsNullMsgs.c:93
const NMMsgDef_T * BsNullMsgDefLookupTbl[]
Definition: bsNullMsgs.c:153
number of fields
Definition: bsNullMsgs.c:113
BsNullRspWriteFId_T
Definition: bsNullMsgs.c:109
static const NMFieldDef_T BsNullReqWriteFieldDefs[]
Definition: bsNullMsgs.c:73
writebuf field id
Definition: bsNullMsgs.c:66
BsNullReqWriteFId_T
Definition: bsNullMsgs.c:63
int BsNullUnpackMsg(BsNullMsgId_T eMsgId, byte_t buf[], size_t uMsgLen, void *pStruct, bool_t bTrace)
Unpack a ITV message in big-endian byte order.
Definition: bsNullMsgs.c:274
static const NMMsgDef_T BsNullRspWriteMsgDef
Definition: bsNullMsgs.c:137
int BsNullPackMsg(BsNullMsgId_T eMsgId, void *pStruct, byte_t buf[], size_t bufSize, bool_t bTrace)
Pack a ITV message in big-endian byte order.
Definition: bsNullMsgs.c:236
static const NMFieldDef_T BsNullRspWriteFieldDefs[]
Definition: bsNullMsgs.c:119
byteswritten field id
Definition: bsNullMsgs.c:112
reserved field id
Definition: bsNullMsgs.c:65
const NMMsgDef_T * BsNullLookupMsgDef(BsNullMsgId_T eMsgId)
Look up the message definition associated with the message id.
Definition: bsNullMsgs.c:186
reserved field id
Definition: bsNullMsgs.c:111
size_t BsNullMsgMaxLenLookupTbl[]
Definition: bsNullMsgs.c:164
number of fields
Definition: bsNullMsgs.c:67
#define EOFDEF
Definition: bsNullMsgs.c:29
#define BSNULL_REQWRITE_WRITEBUF_LEN
Definition: bsNullMsgs.h:54
number of message ids
Definition: bsNullMsgs.h:40
BsNullMsgId_T
Definition: bsNullMsgs.h:35
static const NMFieldDef_T BsNullReqWritewritebufFieldDef[]
Definition: bsNullMsgs.c:45
BotSense bsProxy server - client /dev/null NetMsgs XML Definition.