LTKCPP-- LLRP Toolkit C Plus Plus Library
ltkcpp_xmltext.h
Go to the documentation of this file.
1 
2 /*
3  *****************************************************************************
4  * *
5  * IMPINJ CONFIDENTIAL AND PROPRIETARY *
6  * *
7  * This source code is the sole property of Impinj, Inc. Reproduction or *
8  * utilization of this source code in whole or in part is forbidden without *
9  * the prior written consent of Impinj, Inc. *
10  * *
11  * (c) Copyright Impinj, Inc. 2007,2010. All rights reserved. *
12  * *
13  *****************************************************************************/
14 
15 
28 /* forward declare these so we don't need to include the
29 ** whole XML header files here. Make sure they are out
30 ** of the namespace and extern C since they need to
31 ** match the C types later */
32 extern "C"
33 {
34  struct _xmlNode;
35  struct _xmlDoc;
36 }
37 
38 namespace LLRP
39 {
40 class CXMLTextEncoder;
41 class CXMLTextEncoderStream;
42 class CXMLTextDecoder;
43 class CXMLTextDecoderStream;
44 
45 class CXMLTextEncoder : public CEncoder
46 {
47  friend class CXMLTextEncoderStream;
48 
49  private:
50  char * m_pBuffer;
51  int m_nBuffer;
52  int m_iNext;
53 
54  public:
55  int m_bOverflow;
56 
57  public:
58  CXMLTextEncoder (
59  char * pBuffer,
60  int nBuffer);
61 
62  ~CXMLTextEncoder (void);
63 
64  void
65  encodeElement (
66  const CElement * pElement);
67 };
68 
69 class CXMLTextDecoder : public CDecoder
70 {
71  friend class CXMLTextDecoderStream;
72 
73  private:
74  struct _xmlDoc * m_pDoc;
75  struct _xmlNode * m_pxmlNodeTree;
76 
77  public:
78  CXMLTextDecoder (
79  const CTypeRegistry * pTypeRegistry,
80  char * pBuffer,
81  int nBuffer);
82 
83  CXMLTextDecoder (
84  const CTypeRegistry * pTypeRegistry,
85  struct _xmlNode * pNodeTree);
86 
87 
88  CXMLTextDecoder (
89  const CTypeRegistry * pTypeRegistry,
90  char * fname);
91 
92  ~CXMLTextDecoder (void);
93 
94  CMessage *
95  decodeMessage (void);
96 
124  static void
125  cleanupParser(void);
126 
127 };
128 
129 class CXMLTextEncoderStream : public CEncoderStream
130 {
131  friend class CXMLTextEncoder;
132 
133  public:
134  void
135  putRequiredSubParameter (
136  const CParameter * pParameter,
137  const CTypeDescriptor * pRefType);
138 
139  void
140  putOptionalSubParameter (
141  const CParameter * pParameter,
142  const CTypeDescriptor * pRefType);
143 
144  void
145  putRequiredSubParameterList (
146  const tListOfParameters * pParameterList,
147  const CTypeDescriptor * pRefType);
148 
149  void
150  putOptionalSubParameterList (
151  const tListOfParameters * pParameterList,
152  const CTypeDescriptor * pRefType);
153 
154  /*
155  * 8-bit types
156  */
157 
158  void
159  put_u8 (
160  llrp_u8_t Value,
161  const CFieldDescriptor * pFieldDescriptor);
162 
163  void
164  put_s8 (
165  llrp_s8_t Value,
166  const CFieldDescriptor * pFieldDescriptor);
167 
168  void
169  put_u8v (
170  llrp_u8v_t Value,
171  const CFieldDescriptor * pFieldDescriptor);
172 
173  void
174  put_s8v (
175  llrp_s8v_t Value,
176  const CFieldDescriptor * pFieldDescriptor);
177 
178  /*
179  * 16-bit types
180  */
181 
182  void
183  put_u16 (
184  llrp_u16_t Value,
185  const CFieldDescriptor * pFieldDescriptor);
186 
187  void
188  put_s16 (
189  llrp_s16_t Value,
190  const CFieldDescriptor * pFieldDescriptor);
191 
192  void
193  put_u16v (
194  llrp_u16v_t Value,
195  const CFieldDescriptor * pFieldDescriptor);
196 
197  void
198  put_s16v (
199  llrp_s16v_t Value,
200  const CFieldDescriptor * pFieldDescriptor);
201 
202  /*
203  * 32-bit types
204  */
205 
206  void
207  put_u32 (
208  llrp_u32_t Value,
209  const CFieldDescriptor * pFieldDescriptor);
210 
211  void
212  put_s32 (
213  llrp_s32_t Value,
214  const CFieldDescriptor * pFieldDescriptor);
215 
216  void
217  put_u32v (
218  llrp_u32v_t Value,
219  const CFieldDescriptor * pFieldDescriptor);
220 
221  void
222  put_s32v (
223  llrp_s32v_t Value,
224  const CFieldDescriptor * pFieldDescriptor);
225 
226  /*
227  * 64-bit types
228  */
229 
230  void
231  put_u64 (
232  llrp_u64_t Value,
233  const CFieldDescriptor * pFieldDescriptor);
234 
235  void
236  put_s64 (
237  llrp_s64_t Value,
238  const CFieldDescriptor * pFieldDescriptor);
239 
240  void
241  put_u64v (
242  llrp_u64v_t Value,
243  const CFieldDescriptor * pFieldDescriptor);
244 
245  void
246  put_s64v (
247  llrp_s64v_t Value,
248  const CFieldDescriptor * pFieldDescriptor);
249 
250  /*
251  * Special types
252  */
253 
254  void
255  put_u1 (
256  llrp_u1_t Value,
257  const CFieldDescriptor * pFieldDescriptor);
258 
259  void
260  put_u1v (
261  llrp_u1v_t Value,
262  const CFieldDescriptor * pFieldDescriptor);
263 
264  void
265  put_u2 (
266  llrp_u2_t Value,
267  const CFieldDescriptor * pFieldDescriptor);
268 
269  void
270  put_u96 (
271  llrp_u96_t Value,
272  const CFieldDescriptor * pFieldDescriptor);
273 
274  void
275  put_utf8v (
276  llrp_utf8v_t Value,
277  const CFieldDescriptor * pFieldDescriptor);
278 
279  void
280  put_bytesToEnd (
281  llrp_bytesToEnd_t Value,
282  const CFieldDescriptor * pFieldDescriptor);
283 
284  /*
285  * Enumerated types of various sizes
286  */
287 
288  void
289  put_e1 (
290  int eValue,
291  const CFieldDescriptor * pFieldDescriptor);
292 
293  void
294  put_e2 (
295  int eValue,
296  const CFieldDescriptor * pFieldDescriptor);
297 
298  void
299  put_e8 (
300  int eValue,
301  const CFieldDescriptor * pFieldDescriptor);
302 
303  void
304  put_e16 (
305  int eValue,
306  const CFieldDescriptor * pFieldDescriptor);
307 
308  void
309  put_e32 (
310  int eValue,
311  const CFieldDescriptor * pFieldDescriptor);
312 
313  void
314  put_e8v (
315  llrp_u8v_t Value,
316  const CFieldDescriptor * pFieldDescriptor);
317 
318  /*
319  * Reserved types are some number of bits
320  */
321 
322  void
323  put_reserved (
324  unsigned int nBits);
325 
326  private:
327  CXMLTextEncoderStream (
328  CXMLTextEncoder * pEncoder);
329 
330  CXMLTextEncoderStream (
331  CXMLTextEncoderStream * pEnclosingEncoderStream);
332 
333  CXMLTextEncoder * m_pEncoder;
334  CXMLTextEncoderStream * m_pEnclosingEncoderStream;
335  const CTypeDescriptor * m_pRefType;
336  unsigned int m_nDepth;
337 
338  void
339  putElement (
340  const CElement * pElement);
341 
342  void
343  put_enum (
344  int eValue,
345  const CFieldDescriptor * pFieldDescriptor);
346 
347  void
348  indent(int delta = 0);
349 
350  void
351  appendOpenTag (
352  const char * pName);
353 
354  void
355  appendCloseTag (
356  const char * pName);
357 
358  void
359  appendPrefixedTagName (
360  const char * pName);
361 
362  void
363  appendFormat (
364  char * pFmtStr,
365  ...);
366 
367 };
368 
369 class CXMLTextDecoderStream : public CDecoderStream
370 {
371  friend class CXMLTextDecoder;
372 
373  private:
374  CXMLTextDecoderStream (
375  CXMLTextDecoder * pDecoder);
376 
377  CXMLTextDecoderStream (
378  CXMLTextDecoderStream * pEnclosingDecoderStream);
379 
380  public:
381 
382  CElement *
383  decodeElement (
384  int bAllowMessage,
385  int bSkipBlanks);
386  /*
387  * 8-bit types
388  */
389 
391  llrp_u8_t
392  get_u8 (
393  const CFieldDescriptor * pFieldDesc);
394 
396  llrp_s8_t
397  get_s8 (
398  const CFieldDescriptor * pFieldDesc);
399 
401  llrp_u8v_t
402  get_u8v (
403  const CFieldDescriptor * pFieldDesc);
404 
406  llrp_s8v_t
407  get_s8v (
408  const CFieldDescriptor * pFieldDesc);
409 
410  /*
411  * 16-bit types
412  */
413 
415  llrp_u16_t
416  get_u16 (
417  const CFieldDescriptor * pFieldDesc);
418 
420  llrp_s16_t
421  get_s16 (
422  const CFieldDescriptor * pFieldDesc);
423 
425  llrp_u16v_t
426  get_u16v (
427  const CFieldDescriptor * pFieldDesc);
428 
430  llrp_s16v_t
431  get_s16v (
432  const CFieldDescriptor * pFieldDesc);
433 
434  /*
435  * 32-bit types
436  */
437 
439  llrp_u32_t
440  get_u32 (
441  const CFieldDescriptor * pFieldDesc);
442 
444  llrp_s32_t
445  get_s32 (
446  const CFieldDescriptor * pFieldDesc);
447 
449  llrp_u32v_t
450  get_u32v (
451  const CFieldDescriptor * pFieldDesc);
452 
454  llrp_s32v_t
455  get_s32v (
456  const CFieldDescriptor * pFieldDesc);
457 
458  /*
459  * 64-bit types
460  */
461 
463  llrp_u64_t
464  get_u64 (
465  const CFieldDescriptor * pFieldDesc);
466 
468  llrp_s64_t
469  get_s64 (
470  const CFieldDescriptor * pFieldDesc);
471 
473  llrp_u64v_t
474  get_u64v (
475  const CFieldDescriptor * pFieldDesc);
476 
478  llrp_s64v_t
479  get_s64v (
480  const CFieldDescriptor * pFieldDesc);
481 
482  /*
483  * Special types
484  */
485 
487  llrp_u1_t
488  get_u1 (
489  const CFieldDescriptor * pFieldDesc);
490 
492  llrp_u1v_t
493  get_u1v (
494  const CFieldDescriptor * pFieldDesc);
495 
497  llrp_u2_t
498  get_u2 (
499  const CFieldDescriptor * pFieldDesc);
500 
502  llrp_u96_t
503  get_u96 (
504  const CFieldDescriptor * pFieldDesc);
505 
507  llrp_utf8v_t
508  get_utf8v (
509  const CFieldDescriptor * pFieldDesc);
510 
512  llrp_bytesToEnd_t
513  get_bytesToEnd (
514  const CFieldDescriptor * pFieldDesc);
515 
516  /*
517  * Enumerated types of various sizes
518  */
519 
521  int
522  get_e1 (
523  const CFieldDescriptor * pFieldDesc);
524 
526  int
527  get_e2 (
528  const CFieldDescriptor * pFieldDesc);
529 
531  int
532  get_e8 (
533  const CFieldDescriptor * pFieldDesc);
534 
536  int
537  get_e16 (
538  const CFieldDescriptor * pFieldDesc);
539 
541  int
542  get_e32 (
543  const CFieldDescriptor * pFieldDesc);
544 
546  llrp_u8v_t
547  get_e8v (
548  const CFieldDescriptor * pFieldDesc);
549 
550  /*
551  * Reserved means some number of bits
552  */
553  /* @brief skips a number of reserved bits and discards during the encode/decode process */
554  void
555  get_reserved (
556  unsigned int nBits);
557 
558  private:
559  CXMLTextDecoder * m_pDecoder;
560  CXMLTextDecoderStream * m_pEnclosingDecoderStream;
561  const CTypeDescriptor * m_pRefType;
562  struct _xmlNode * m_pTargetNode;
563  struct _xmlNode * m_pCurrentChildNode;
564  struct _xmlNode * m_pLastFieldNode;
565 
566  llrp_bool_t
567  verifyVectorAllocation (
568  const void * pValue,
569  const CFieldDescriptor * pFieldDescriptor);
570 
571  static int
572  isInsignificantNode (
573  struct _xmlNode * pnode);
574 
575 /* some class member field helpers */
576  int
577  getFieldStringPtr(
578  const CFieldDescriptor * pFieldDescriptor,
579  const llrp_u8_t ** pbuf,
580  const llrp_u8_t ** pend);
581 
582  llrp_s64v_t
583  getSpacedVectorField (
584  const CFieldDescriptor * pFieldDescriptor,
585  llrp_s64_t minValue,
586  llrp_s64_t maxValue);
587 
588  llrp_s64v_t
589  getFixedVectorField (
590  const CFieldDescriptor * pFieldDescriptor,
591  unsigned int vectorSize,
592  llrp_s64_t minValue,
593  llrp_s64_t maxValue);
594 
595  llrp_s64_t
596  getIntegerField (
597  const CFieldDescriptor * pFieldDescriptor,
598  llrp_s64_t minValue,
599  llrp_s64_t maxValue);
600 
601  llrp_s64_t getInteger(
602  const CFieldDescriptor * pFieldDescriptor,
603  const llrp_u8_t * pbuf,
604  const llrp_u8_t * pend,
605  CErrorDetails *pError,
606  llrp_s64_t minValue,
607  llrp_s64_t maxValue);
608 
609 /* static string helpers */
610 
611  static const llrp_u8_t *
612  getSingleU1(
613  const llrp_u8_t * pbuf,
614  const llrp_u8_t * pend,
615  llrp_s64_t * pValue);
616 
617  static const llrp_u8_t *
618  getSingleEnum(
619  const CFieldDescriptor * pFieldDescriptor,
620  const llrp_u8_t * pbuf,
621  const llrp_u8_t * pend,
622  llrp_s64_t * pValue);
623 
624  static const llrp_u8_t *
625  getSingleDecimal(
626  const llrp_u8_t * pbuf,
627  const llrp_u8_t * pend,
628  llrp_s64_t * pValue);
629 
630  static const llrp_u8_t *
631  getSingleHexidecimal(
632  const llrp_u8_t * pbuf,
633  const llrp_u8_t * pend,
634  llrp_s64_t * pValue);
635 
636  static int
637  cleanString(
638  const llrp_u8_t ** ppbuf,
639  const llrp_u8_t ** ppend);
640 
641  static const llrp_u8_t *
642  getSingleTimestamp(
643  const llrp_u8_t * pbuf,
644  const llrp_u8_t * pend,
645  llrp_s64_t * pValue);
646 
647  static llrp_u16_t
648  countElements(
649  const char * pval,
650  int nval);
651 
652  private:
653  static const llrp_s64_t MAX_U8 = ((1ull << 8u) - 1u);
654  static const llrp_s64_t MIN_U8 = 0ull;
655  static const llrp_s64_t MAX_S8 = ((1ull << 7u) - 1u);
656  static const llrp_s64_t MIN_S8 = (-1ll - MAX_S8);
657 
658  static const llrp_s64_t MAX_U16 = ((1ull << 16u) - 1u);
659  static const llrp_s64_t MIN_U16 = 0ull;
660  static const llrp_s64_t MAX_S16 = ((1ull << 15u) - 1u);
661  static const llrp_s64_t MIN_S16 = (-1ll - MAX_S16);
662 
663  static const llrp_s64_t MAX_U32 = ((1ull << 32u) - 1u);
664  static const llrp_s64_t MIN_U32 = 0ull;
665  static const llrp_s64_t MAX_S32 = ((1ull << 31u) - 1u);
666  static const llrp_s64_t MIN_S32 = (-1ll - MAX_S32);
667 
668  static const llrp_s64_t MAX_U64 = ((1ull << 63u) - 1u); // one bit lost
669  static const llrp_s64_t MIN_U64 = 0ull;
670  static const llrp_s64_t MAX_S64 = ((1ull << 63u) - 1u);
671  static const llrp_s64_t MIN_S64 = (-1ll - MAX_S64);
672 
673 };
674 
675 };
Definition: ltkcpp.h:45