sbgECom Library  4.0.1987-stable
C library to interface SBG Systems IMU/AHRS/INS
sbgStreamBufferLE.h
Go to the documentation of this file.
1 
33 #ifndef SBG_STREAM_BUFFER_LE_H
34 #define SBG_STREAM_BUFFER_LE_H
35 
36 #include "sbgStreamBufferCommon.h"
37 
38 //----------------------------------------------------------------------//
39 //- Read operations methods -//
40 //----------------------------------------------------------------------//
41 
49 {
50  int16_t bytesValues[2];
51 
52  assert(pHandle);
53 
54  //
55  // Test if we haven't already an error
56  //
57  if (pHandle->errorCode == SBG_NO_ERROR)
58  {
59  //
60  // Test if we can access this item
61  //
62  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int16_t))
63  {
64  //
65  // Test if the platform supports un-aligned access and if the endianness is the same
66  //
67  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
68  //
69  // Read the current value
70  //
71  bytesValues[0] = *((int16_t*)pHandle->pCurrentPtr);
72 
73  //
74  // Increment the current pointer
75  //
76  pHandle->pCurrentPtr += sizeof(int16_t);
77 
78  return bytesValues[0];
79  #else
80  //
81  // Read the each bytes
82  //
83  bytesValues[0] = *(pHandle->pCurrentPtr++);
84  bytesValues[1] = *(pHandle->pCurrentPtr++);
85 
86  //
87  // Store data according to platform endianness
88  //
89  #if (SBG_CONFIG_BIG_ENDIAN == 1)
90  return bytesValues[1] | (bytesValues[0] << 8);
91  #else
92  return bytesValues[0] | (bytesValues[1] << 8);
93  #endif
94  #endif
95  }
96  else
97  {
98  //
99  // We have a buffer overflow so return 0
100  //
101  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
102  }
103  }
104 
105  //
106  // If we are here, it means we have an error so return 0
107  //
108  return 0;
109 }
110 
118 {
119  uint16_t bytesValues[2];
120 
121  assert(pHandle);
122 
123  //
124  // Test if we haven't already an error
125  //
126  if (pHandle->errorCode == SBG_NO_ERROR)
127  {
128  //
129  // Test if we can access this item
130  //
131  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint16_t))
132  {
133  //
134  // Test if the platform supports un-aligned access and if the endianness is the same
135  //
136  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
137  //
138  // Read the current value
139  //
140  bytesValues[0] = *((uint16_t*)pHandle->pCurrentPtr);
141 
142  //
143  // Increment the current pointer
144  //
145  pHandle->pCurrentPtr += sizeof(uint16_t);
146 
147  return bytesValues[0];
148  #else
149  //
150  // Read the each bytes
151  //
152  bytesValues[0] = *(pHandle->pCurrentPtr++);
153  bytesValues[1] = *(pHandle->pCurrentPtr++);
154 
155  //
156  // Store data according to platform endianness
157  //
158  #if (SBG_CONFIG_BIG_ENDIAN == 1)
159  return bytesValues[1] | (bytesValues[0] << 8);
160  #else
161  return bytesValues[0] | (bytesValues[1] << 8);
162  #endif
163  #endif
164  }
165  else
166  {
167  //
168  // We have a buffer overflow so return 0
169  //
170  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
171  }
172  }
173 
174  //
175  // If we are here, it means we have an error so return 0
176  //
177  return 0;
178 }
179 
187 {
188  SbgUint8ToInt32 value;
189 
190  assert(pHandle);
191 
192  //
193  // Test if we haven't already an error
194  //
195  if (pHandle->errorCode == SBG_NO_ERROR)
196  {
197  //
198  // Test if we can access this item
199  //
200  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(uint8_t))
201  {
202  //
203  // Make sure the value is zero init
204  //
205  value.value = 0;
206 
207  //
208  // Store data according to platform endianness
209  //
210  #if (SBG_CONFIG_BIG_ENDIAN == 1)
211  //
212  // Read the each bytes
213  //
214  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
215  value.buffer[1] = *(pHandle->pCurrentPtr++);
216  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
217  #else
218  //
219  // Read the each bytes
220  //
221  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
222  value.buffer[2] = *(pHandle->pCurrentPtr++);
223  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
224  #endif
225 
226  //
227  // Shift the value to handle the sign correctly for a 24 bits
228  //
229  return value.value >> (32-24);
230  }
231  else
232  {
233  //
234  // We have a buffer overflow so return 0
235  //
236  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
237  }
238  }
239 
240  //
241  // If we are here, it means we have an error so return 0
242  //
243  return 0;
244 }
245 
253 {
254  SbgUint8ToUint32 value;
255 
256  assert(pHandle);
257 
258  //
259  // Test if we haven't already an error
260  //
261  if (pHandle->errorCode == SBG_NO_ERROR)
262  {
263  //
264  // Test if we can access this item
265  //
266  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(uint8_t))
267  {
268  //
269  // Make sure the value is zero init
270  //
271  value.value = 0;
272 
273  //
274  // Store data according to platform endianness
275  //
276  #if (SBG_CONFIG_BIG_ENDIAN == 1)
277  //
278  // Read the each bytes
279  //
280  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
281  value.buffer[1] = *(pHandle->pCurrentPtr++);
282  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
283  #else
284  //
285  // Read the each bytes
286  //
287  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
288  value.buffer[2] = *(pHandle->pCurrentPtr++);
289  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
290  #endif
291 
292  //
293  // Shift the value to handle the sign correctly for a 24 bits
294  //
295  return value.value >> (32-24);
296  }
297  else
298  {
299  //
300  // We have a buffer overflow so return 0
301  //
302  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
303  }
304  }
305 
306  //
307  // If we are here, it means we have an error so return 0
308  //
309  return 0;
310 }
311 
319 {
320  int32_t bytesValues[4];
321 
322  assert(pHandle);
323 
324  //
325  // Test if we haven't already an error
326  //
327  if (pHandle->errorCode == SBG_NO_ERROR)
328  {
329  //
330  // Test if we can access this item
331  //
332  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int32_t))
333  {
334  //
335  // Test if the platform supports un-aligned access and if the endianness is the same
336  //
337  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
338  //
339  // Read the current value
340  //
341  bytesValues[0] = *((int32_t*)pHandle->pCurrentPtr);
342 
343  //
344  // Increment the current pointer
345  //
346  pHandle->pCurrentPtr += sizeof(int32_t);
347 
348  return bytesValues[0];
349  #else
350  //
351  // Read the each bytes
352  //
353  bytesValues[0] = *(pHandle->pCurrentPtr++);
354  bytesValues[1] = *(pHandle->pCurrentPtr++);
355  bytesValues[2] = *(pHandle->pCurrentPtr++);
356  bytesValues[3] = *(pHandle->pCurrentPtr++);
357 
358  //
359  // Store data according to platform endianness
360  //
361  #if (SBG_CONFIG_BIG_ENDIAN == 1)
362  return bytesValues[3] | (bytesValues[2] << 8) | (bytesValues[1] << 16) | (bytesValues[0] << 24);
363  #else
364  return bytesValues[0] | (bytesValues[1] << 8) | (bytesValues[2] << 16) | (bytesValues[3] << 24);
365  #endif
366  #endif
367  }
368  else
369  {
370  //
371  // We have a buffer overflow so return 0
372  //
373  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
374  }
375  }
376 
377  //
378  // If we are here, it means we have an error so return 0
379  //
380  return 0;
381 }
382 
390 {
391  uint32_t bytesValues[4];
392 
393  assert(pHandle);
394 
395  //
396  // Test if we haven't already an error
397  //
398  if (pHandle->errorCode == SBG_NO_ERROR)
399  {
400  //
401  // Test if we can access this item
402  //
403  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint32_t))
404  {
405  //
406  // Test if the platform supports un-aligned access and if the endianness is the same
407  //
408  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
409  //
410  // Read the current value
411  //
412  bytesValues[0] = *((uint32_t*)pHandle->pCurrentPtr);
413 
414  //
415  // Increment the current pointer
416  //
417  pHandle->pCurrentPtr += sizeof(uint32_t);
418 
419  return bytesValues[0];
420  #else
421  //
422  // Read the each bytes
423  //
424  bytesValues[0] = *(pHandle->pCurrentPtr++);
425  bytesValues[1] = *(pHandle->pCurrentPtr++);
426  bytesValues[2] = *(pHandle->pCurrentPtr++);
427  bytesValues[3] = *(pHandle->pCurrentPtr++);
428 
429  //
430  // Store data according to platform endianness
431  //
432  #if (SBG_CONFIG_BIG_ENDIAN == 1)
433  return bytesValues[3] | (bytesValues[2] << 8) | (bytesValues[1] << 16) | (bytesValues[0] << 24);
434  #else
435  return bytesValues[0] | (bytesValues[1] << 8) | (bytesValues[2] << 16) | (bytesValues[3] << 24);
436  #endif
437  #endif
438  }
439  else
440  {
441  //
442  // We have a buffer overflow so return 0
443  //
444  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
445  }
446  }
447 
448  //
449  // If we are here, it means we have an error so return 0
450  //
451  return 0;
452 }
453 
461 {
462  SbgUint8ToInt64 value;
463 
464  assert(pHandle);
465 
466  //
467  // Test if we haven't already an error
468  //
469  if (pHandle->errorCode == SBG_NO_ERROR)
470  {
471  //
472  // Test if we can access this item
473  //
474  if (sbgStreamBufferGetSpace(pHandle) >= 5*sizeof(uint8_t))
475  {
476  //
477  // Make sure the value is zero init
478  //
479  value.value = 0;
480 
481  //
482  // Store data according to platform endianness
483  //
484  #if (SBG_CONFIG_BIG_ENDIAN == 1)
485  //
486  // Read the each bytes
487  //
488  value.buffer[4] = *(pHandle->pCurrentPtr++); // LSB
489  value.buffer[3] = *(pHandle->pCurrentPtr++);
490  value.buffer[2] = *(pHandle->pCurrentPtr++);
491  value.buffer[1] = *(pHandle->pCurrentPtr++);
492  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
493  #else
494  //
495  // Read the each bytes
496  //
497  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
498  value.buffer[4] = *(pHandle->pCurrentPtr++);
499  value.buffer[5] = *(pHandle->pCurrentPtr++);
500  value.buffer[6] = *(pHandle->pCurrentPtr++);
501  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
502  #endif
503 
504  //
505  // Shift the value to handle the sign correctly for a 40 bits
506  //
507  return value.value >> (64-40);
508  }
509  else
510  {
511  //
512  // We have a buffer overflow so return 0
513  //
514  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
515  }
516  }
517 
518  //
519  // If we are here, it means we have an error so return 0
520  //
521  return 0;
522 }
523 
531 {
532  SbgUint8ToUint64 value;
533 
534  assert(pHandle);
535 
536  //
537  // Test if we haven't already an error
538  //
539  if (pHandle->errorCode == SBG_NO_ERROR)
540  {
541  //
542  // Test if we can access this item
543  //
544  if (sbgStreamBufferGetSpace(pHandle) >= 5*sizeof(uint8_t))
545  {
546  //
547  // Make sure the value is zero init
548  //
549  value.value = 0;
550 
551  //
552  // Store data according to platform endianness
553  //
554  #if (SBG_CONFIG_BIG_ENDIAN == 1)
555  //
556  // Read the each bytes
557  //
558  value.buffer[4] = *(pHandle->pCurrentPtr++); // LSB
559  value.buffer[3] = *(pHandle->pCurrentPtr++);
560  value.buffer[2] = *(pHandle->pCurrentPtr++);
561  value.buffer[1] = *(pHandle->pCurrentPtr++);
562  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
563  #else
564  //
565  // Read the each bytes
566  //
567  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
568  value.buffer[4] = *(pHandle->pCurrentPtr++);
569  value.buffer[5] = *(pHandle->pCurrentPtr++);
570  value.buffer[6] = *(pHandle->pCurrentPtr++);
571  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
572  #endif
573 
574  //
575  // Shift the value to handle the sign correctly for a 40 bits
576  //
577  return value.value >> (64-40);
578  }
579  else
580  {
581  //
582  // We have a buffer overflow so return 0
583  //
584  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
585  }
586  }
587 
588  //
589  // If we are here, it means we have an error so return 0
590  //
591  return 0;
592 }
593 
601 {
602  SbgUint8ToInt64 value;
603 
604  assert(pHandle);
605 
606  //
607  // Test if we haven't already an error
608  //
609  if (pHandle->errorCode == SBG_NO_ERROR)
610  {
611  //
612  // Test if we can access this item
613  //
614  if (sbgStreamBufferGetSpace(pHandle) >= 6*sizeof(uint8_t))
615  {
616  //
617  // Make sure the value is zero init
618  //
619  value.value = 0;
620 
621  //
622  // Store data according to platform endianness
623  //
624  #if (SBG_CONFIG_BIG_ENDIAN == 1)
625  //
626  // Read the each bytes
627  //
628  value.buffer[5] = *(pHandle->pCurrentPtr++); // LSB
629  value.buffer[4] = *(pHandle->pCurrentPtr++);
630  value.buffer[3] = *(pHandle->pCurrentPtr++);
631  value.buffer[2] = *(pHandle->pCurrentPtr++);
632  value.buffer[1] = *(pHandle->pCurrentPtr++);
633  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
634  #else
635  //
636  // Read the each bytes
637  //
638  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
639  value.buffer[3] = *(pHandle->pCurrentPtr++);
640  value.buffer[4] = *(pHandle->pCurrentPtr++);
641  value.buffer[5] = *(pHandle->pCurrentPtr++);
642  value.buffer[6] = *(pHandle->pCurrentPtr++);
643  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
644  #endif
645 
646  //
647  // Shift the value to handle the sign correctly for a 48 bits
648  //
649  return value.value >> (64-48);
650  }
651  else
652  {
653  //
654  // We have a buffer overflow so return 0
655  //
656  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
657  }
658  }
659 
660  //
661  // If we are here, it means we have an error so return 0
662  //
663  return 0;
664 }
665 
673 {
674  SbgUint8ToUint64 value;
675 
676  assert(pHandle);
677 
678  //
679  // Test if we haven't already an error
680  //
681  if (pHandle->errorCode == SBG_NO_ERROR)
682  {
683  //
684  // Test if we can access this item
685  //
686  if (sbgStreamBufferGetSpace(pHandle) >= 6*sizeof(uint8_t))
687  {
688  //
689  // Make sure the value is zero init
690  //
691  value.value = 0;
692 
693  //
694  // Store data according to platform endianness
695  //
696  #if (SBG_CONFIG_BIG_ENDIAN == 1)
697  //
698  // Read the each bytes
699  //
700  value.buffer[5] = *(pHandle->pCurrentPtr++); // LSB
701  value.buffer[4] = *(pHandle->pCurrentPtr++);
702  value.buffer[3] = *(pHandle->pCurrentPtr++);
703  value.buffer[2] = *(pHandle->pCurrentPtr++);
704  value.buffer[1] = *(pHandle->pCurrentPtr++);
705  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
706  #else
707  //
708  // Read the each bytes
709  //
710  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
711  value.buffer[3] = *(pHandle->pCurrentPtr++);
712  value.buffer[4] = *(pHandle->pCurrentPtr++);
713  value.buffer[5] = *(pHandle->pCurrentPtr++);
714  value.buffer[6] = *(pHandle->pCurrentPtr++);
715  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
716  #endif
717 
718  //
719  // Shift the value to handle the sign correctly for a 48 bits
720  //
721  return value.value >> (64-48);
722  }
723  else
724  {
725  //
726  // We have a buffer overflow so return 0
727  //
728  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
729  }
730  }
731 
732  //
733  // If we are here, it means we have an error so return 0
734  //
735  return 0;
736 }
737 
745 {
746  SbgUint8ToInt64 value;
747 
748  assert(pHandle);
749 
750  //
751  // Test if we haven't already an error
752  //
753  if (pHandle->errorCode == SBG_NO_ERROR)
754  {
755  //
756  // Test if we can access this item
757  //
758  if (sbgStreamBufferGetSpace(pHandle) >= 7*sizeof(uint8_t))
759  {
760  //
761  // Make sure the value is zero init
762  //
763  value.value = 0;
764 
765  //
766  // Store data according to platform endianness
767  //
768  #if (SBG_CONFIG_BIG_ENDIAN == 1)
769  //
770  // Read the each bytes
771  //
772  value.buffer[6] = *(pHandle->pCurrentPtr++); // LSB
773  value.buffer[5] = *(pHandle->pCurrentPtr++);
774  value.buffer[4] = *(pHandle->pCurrentPtr++);
775  value.buffer[3] = *(pHandle->pCurrentPtr++);
776  value.buffer[2] = *(pHandle->pCurrentPtr++);
777  value.buffer[1] = *(pHandle->pCurrentPtr++);
778  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
779  #else
780  //
781  // Read the each bytes
782  //
783  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
784  value.buffer[2] = *(pHandle->pCurrentPtr++);
785  value.buffer[3] = *(pHandle->pCurrentPtr++);
786  value.buffer[4] = *(pHandle->pCurrentPtr++);
787  value.buffer[5] = *(pHandle->pCurrentPtr++);
788  value.buffer[6] = *(pHandle->pCurrentPtr++);
789  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
790  #endif
791 
792  //
793  // Shift the value to handle the sign correctly for a 56 bits
794  //
795  return value.value >> (64-56);
796  }
797  else
798  {
799  //
800  // We have a buffer overflow so return 0
801  //
802  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
803  }
804  }
805 
806  //
807  // If we are here, it means we have an error so return 0
808  //
809  return 0;
810 }
811 
819 {
820  SbgUint8ToUint64 value;
821 
822  assert(pHandle);
823 
824  //
825  // Test if we haven't already an error
826  //
827  if (pHandle->errorCode == SBG_NO_ERROR)
828  {
829  //
830  // Test if we can access this item
831  //
832  if (sbgStreamBufferGetSpace(pHandle) >= 7*sizeof(uint8_t))
833  {
834  //
835  // Make sure the value is zero init
836  //
837  value.value = 0;
838 
839  //
840  // Store data according to platform endianness
841  //
842  #if (SBG_CONFIG_BIG_ENDIAN == 1)
843  //
844  // Read the each bytes
845  //
846  value.buffer[6] = *(pHandle->pCurrentPtr++); // LSB
847  value.buffer[5] = *(pHandle->pCurrentPtr++);
848  value.buffer[4] = *(pHandle->pCurrentPtr++);
849  value.buffer[3] = *(pHandle->pCurrentPtr++);
850  value.buffer[2] = *(pHandle->pCurrentPtr++);
851  value.buffer[1] = *(pHandle->pCurrentPtr++);
852  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
853  #else
854  //
855  // Read the each bytes
856  //
857  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
858  value.buffer[2] = *(pHandle->pCurrentPtr++);
859  value.buffer[3] = *(pHandle->pCurrentPtr++);
860  value.buffer[4] = *(pHandle->pCurrentPtr++);
861  value.buffer[5] = *(pHandle->pCurrentPtr++);
862  value.buffer[6] = *(pHandle->pCurrentPtr++);
863  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
864  #endif
865 
866  //
867  // Shift the value to handle the sign correctly for a 56 bits
868  //
869  return value.value >> (64-56);
870  }
871  else
872  {
873  //
874  // We have a buffer overflow so return 0
875  //
876  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
877  }
878  }
879 
880  //
881  // If we are here, it means we have an error so return 0
882  //
883  return 0;
884 }
885 
893 {
894  int64_t lowPart;
895  int64_t highPart;
896 
897  assert(pHandle);
898 
899  //
900  // Test if we haven't already an error
901  //
902  if (pHandle->errorCode == SBG_NO_ERROR)
903  {
904  //
905  // Test if we can access this item
906  //
907  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int64_t))
908  {
909  //
910  // Test if the platform supports un-aligned access and if the endianness is the same
911  //
912  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
913  //
914  // Read the current value
915  //
916  lowPart = *((int64_t*)pHandle->pCurrentPtr);
917 
918  //
919  // Increment the current pointer
920  //
921  pHandle->pCurrentPtr += sizeof(int64_t);
922 
923  return lowPart;
924  #else
925  //
926  // Read 64 bit value using two 32 bits read to avoid too much 64 bits operations
927  //
928  lowPart = sbgStreamBufferReadUint32LE(pHandle);
929  highPart = sbgStreamBufferReadUint32LE(pHandle);
930 
931  //
932  // Store data according to platform endianness
933  //
934  #if (SBG_CONFIG_BIG_ENDIAN == 1)
935  return (lowPart << 32) | highPart;
936  #else
937  return lowPart | (highPart << 32);
938  #endif
939  #endif
940  }
941  else
942  {
943  //
944  // We have a buffer overflow so return 0
945  //
946  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
947  }
948  }
949 
950  //
951  // If we are here, it means we have an error so return 0
952  //
953  return 0ll;
954 }
955 
963 {
964  uint64_t lowPart;
965  uint64_t highPart;
966 
967  assert(pHandle);
968 
969  //
970  // Test if we haven't already an error
971  //
972  if (pHandle->errorCode == SBG_NO_ERROR)
973  {
974  //
975  // Test if we can access this item
976  //
977  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint64_t))
978  {
979  //
980  // Test if the platform supports un-aligned access and if the endianness is the same
981  //
982  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
983  //
984  // Read the current value
985  //
986  lowPart = *((uint64_t*)pHandle->pCurrentPtr);
987 
988  //
989  // Increment the current pointer
990  //
991  pHandle->pCurrentPtr += sizeof(uint64_t);
992 
993  return lowPart;
994  #else
995  //
996  // Read 64 bit value using two 32 bits read to avoid too much 64 bits operations
997  //
998  lowPart = sbgStreamBufferReadUint32LE(pHandle);
999  highPart = sbgStreamBufferReadUint32LE(pHandle);
1000 
1001  //
1002  // Store data according to platform endianness
1003  //
1004  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1005  return (lowPart << 32) | highPart;
1006  #else
1007  return lowPart | (highPart << 32);
1008  #endif
1009  #endif
1010  }
1011  else
1012  {
1013  //
1014  // We have a buffer overflow so return 0
1015  //
1016  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1017  }
1018  }
1019 
1020  //
1021  // If we are here, it means we have an error so return 0
1022  //
1023  return 0ull;
1024 }
1025 
1033 {
1034  assert(pHandle);
1035 
1036  //
1037  // Just call the read method for uint32_t
1038  // We assume that a size_t is at least 32 bits on all platforms
1039  //
1040  return (size_t)sbgStreamBufferReadUint32LE(pHandle);
1041 }
1042 
1050 {
1051  uint64_t size;
1052 
1053  assert(pHandle);
1054 
1055  //
1056  // Just call the read method for uint64_t
1057  //
1058  size = sbgStreamBufferReadUint64LE(pHandle);
1059 
1060  //
1061  // Make sure the read size can fit in the size_t in size_t is 32 bits
1062  //
1063  assert((sizeof(size_t) == 8) || ((sizeof(size_t) == 4) && (size <= UINT32_MAX)));
1064 
1065  //
1066  // Return the read value
1067  //
1068  return (size_t)size;
1069 }
1070 
1078 {
1079  SbgFloatNint floatInt;
1080 
1081  assert(pHandle);
1082 
1083  //
1084  // Test if we haven't already an error
1085  //
1086  if (pHandle->errorCode == SBG_NO_ERROR)
1087  {
1088  //
1089  // Test if we can access this item
1090  //
1091  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(float))
1092  {
1093  //
1094  // Read the float as an uint32_t
1095  //
1096  floatInt.valU = sbgStreamBufferReadUint32LE(pHandle);
1097 
1098  //
1099  // Return the float using an union to avoid compiler cast
1100  //
1101  return floatInt.valF;
1102  }
1103  else
1104  {
1105  //
1106  // We have a buffer overflow so return 0
1107  //
1108  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1109  }
1110  }
1111 
1112  //
1113  // If we are here, it means we have an error so return 0
1114  //
1115  return 0.0f;
1116 }
1117 
1125 {
1126  SbgDoubleNint doubleInt;
1127 
1128  assert(pHandle);
1129 
1130  //
1131  // Test if we haven't already an error
1132  //
1133  if (pHandle->errorCode == SBG_NO_ERROR)
1134  {
1135  //
1136  // Test if we can access this item
1137  //
1138  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(double))
1139  {
1140  //
1141  // Read the float as an uint64_t
1142  //
1143  doubleInt.valU = sbgStreamBufferReadUint64LE(pHandle);
1144 
1145  //
1146  // Return the double using an union to avoid compiler cast
1147  //
1148  return doubleInt.valF;
1149  }
1150  else
1151  {
1152  //
1153  // We have a buffer overflow so return 0
1154  //
1155  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1156  }
1157  }
1158 
1159  //
1160  // If we are here, it means we have an error so return 0
1161  //
1162  return 0.0;
1163 }
1164 
1165 //----------------------------------------------------------------------//
1166 //- Write operations methods -//
1167 //----------------------------------------------------------------------//
1168 
1177 {
1178  assert(pHandle);
1179 
1180  //
1181  // Test if we haven't already an error
1182  //
1183  if (pHandle->errorCode == SBG_NO_ERROR)
1184  {
1185  //
1186  // Test if we can access this item
1187  //
1188  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int16_t))
1189  {
1190  //
1191  // Test if the platform supports un-aligned access and if the endianness is the same
1192  //
1193  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1194  //
1195  // Write the value
1196  //
1197  *((int16_t*)(pHandle->pCurrentPtr)) = value;
1198 
1199  //
1200  // Increment the current pointer
1201  //
1202  pHandle->pCurrentPtr += sizeof(int16_t);
1203  #else
1204  //
1205  // Store data according to platform endianness
1206  //
1207  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1208  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1209  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1210  #else
1211  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1212  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1213  #endif
1214  #endif
1215  }
1216  else
1217  {
1218  //
1219  // We are accessing a data that is outside the stream buffer
1220  //
1221  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1222  }
1223  }
1224 
1225  return pHandle->errorCode;
1226 }
1227 
1236 {
1237  assert(pHandle);
1238 
1239  //
1240  // Test if we haven't already an error
1241  //
1242  if (pHandle->errorCode == SBG_NO_ERROR)
1243  {
1244  //
1245  // Test if we can access this item
1246  //
1247  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint16_t))
1248  {
1249  //
1250  // Test if the platform supports un-aligned access and if the endianness is the same
1251  //
1252  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1253  //
1254  // Write the value
1255  //
1256  *((uint16_t*)(pHandle->pCurrentPtr)) = value;
1257 
1258  //
1259  // Increment the current pointer
1260  //
1261  pHandle->pCurrentPtr += sizeof(uint16_t);
1262  #else
1263  //
1264  // Store data according to platform endianness
1265  //
1266  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1267  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1268  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1269  #else
1270  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1271  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1272  #endif
1273  #endif
1274  }
1275  else
1276  {
1277  //
1278  // We are accessing a data that is outside the stream buffer
1279  //
1280  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1281  }
1282  }
1283 
1284  return pHandle->errorCode;
1285 }
1286 
1287 
1296 {
1297  assert(pHandle);
1298 
1299  //
1300  // Test if we haven't already an error
1301  //
1302  if (pHandle->errorCode == SBG_NO_ERROR)
1303  {
1304  //
1305  // Make sure that the value is within 24 bit bonds
1306  //
1307  if ( (value >= SBG_MIN_INT_24) && (value <= SBG_MAX_INT_24) )
1308  {
1309  //
1310  // Test if we can access this item
1311  //
1312  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(int8_t))
1313  {
1314  //
1315  // Store data according to platform endianness
1316  //
1317  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1318  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1319  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1320  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1321  #else
1322  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1323  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1324  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1325  #endif
1326  }
1327  else
1328  {
1329  //
1330  // We are accessing a data that is outside the stream buffer
1331  //
1332  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1333  }
1334  }
1335  else
1336  {
1337  //
1338  // The input value is not within a 24 bit integer bounds
1339  //
1340  pHandle->errorCode = SBG_INVALID_PARAMETER;
1341  }
1342  }
1343 
1344  return pHandle->errorCode;
1345 }
1346 
1355 {
1356  assert(pHandle);
1357 
1358  //
1359  // Test if we haven't already an error
1360  //
1361  if (pHandle->errorCode == SBG_NO_ERROR)
1362  {
1363  //
1364  // Make sure that the value is within 24 bit bonds
1365  //
1366  if (value <= SBG_MAX_UINT_24)
1367  {
1368  //
1369  // Test if we can access this item
1370  //
1371  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(uint8_t))
1372  {
1373  //
1374  // Store data according to platform endianness
1375  //
1376  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1377  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1378  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1379  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1380  #else
1381  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1382  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1383  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1384  #endif
1385  }
1386  else
1387  {
1388  //
1389  // We are accessing a data that is outside the stream buffer
1390  //
1391  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1392  }
1393  }
1394  else
1395  {
1396  //
1397  // The input value is not within a 24 bit integer bounds
1398  //
1399  pHandle->errorCode = SBG_INVALID_PARAMETER;
1400  }
1401  }
1402 
1403  return pHandle->errorCode;
1404 }
1405 
1414 {
1415  assert(pHandle);
1416 
1417  //
1418  // Test if we haven't already an error
1419  //
1420  if (pHandle->errorCode == SBG_NO_ERROR)
1421  {
1422  //
1423  // Test if we can access this item
1424  //
1425  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int32_t))
1426  {
1427  //
1428  // Test if the platform supports un-aligned access and if the endianness is the same
1429  //
1430  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1431  //
1432  // Write the value
1433  //
1434  *((int32_t*)(pHandle->pCurrentPtr)) = value;
1435 
1436  //
1437  // Increment the current pointer
1438  //
1439  pHandle->pCurrentPtr += sizeof(int32_t);
1440  #else
1441  //
1442  // Store data according to platform endianness
1443  //
1444  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1445  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1446  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1447  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1448  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1449  #else
1450  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1451  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1452  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1453  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1454  #endif
1455  #endif
1456  }
1457  else
1458  {
1459  //
1460  // We are accessing a data that is outside the stream buffer
1461  //
1462  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1463  }
1464  }
1465 
1466  return pHandle->errorCode;
1467 }
1468 
1477 {
1478  assert(pHandle);
1479 
1480  //
1481  // Test if we haven't already an error
1482  //
1483  if (pHandle->errorCode == SBG_NO_ERROR)
1484  {
1485  //
1486  // Test if we can access this item
1487  //
1488  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint32_t))
1489  {
1490  //
1491  // Test if the platform supports un-aligned access and if the endianness is the same
1492  //
1493  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1494  //
1495  // Write the value
1496  //
1497  *((uint32_t*)(pHandle->pCurrentPtr)) = value;
1498 
1499  //
1500  // Increment the current pointer
1501  //
1502  pHandle->pCurrentPtr += sizeof(uint32_t);
1503  #else
1504  //
1505  // Store data according to platform endianness
1506  //
1507  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1508  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1509  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1510  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1511  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1512  #else
1513  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1514  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1515  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1516  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1517  #endif
1518  #endif
1519  }
1520  else
1521  {
1522  //
1523  // We are accessing a data that is outside the stream buffer
1524  //
1525  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1526  }
1527  }
1528 
1529  return pHandle->errorCode;
1530 }
1531 
1540 {
1541  assert(pHandle);
1542  assert(value < ((uint64_t)1 << 48));
1543 
1544  //
1545  // Test if we haven't already an error
1546  //
1547  if (pHandle->errorCode == SBG_NO_ERROR)
1548  {
1549  //
1550  // Test if we can access this item
1551  //
1552  if (sbgStreamBufferGetSpace(pHandle) >= 6 * sizeof(uint8_t))
1553  {
1554  //
1555  // Store data according to platform endianness
1556  //
1557  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1558  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1559  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1560  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1561  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1562  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1563  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1564  #else
1565  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1566  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1567  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1568  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1569  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1570  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1571  #endif
1572  }
1573  else
1574  {
1575  //
1576  // We are accessing a data that is outside the stream buffer
1577  //
1578  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1579  }
1580  }
1581 
1582  return pHandle->errorCode;
1583 }
1584 
1593 {
1594  assert(pHandle);
1595 
1596  //
1597  // Test if we haven't already an error
1598  //
1599  if (pHandle->errorCode == SBG_NO_ERROR)
1600  {
1601  //
1602  // Test if we can access this item
1603  //
1604  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int64_t))
1605  {
1606  //
1607  // Test if the platform supports un-aligned access and if the endianness is the same
1608  //
1609  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1610  //
1611  // Write the value
1612  //
1613  *((int64_t*)(pHandle->pCurrentPtr)) = value;
1614 
1615  //
1616  // Increment the current pointer
1617  //
1618  pHandle->pCurrentPtr += sizeof(int64_t);
1619  #else
1620  //
1621  // Store data according to platform endianness
1622  //
1623  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1624  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1625  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1626  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1627  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1628  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1629  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1630  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1631  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1632  #else
1633  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1634  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1635  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1636  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1637  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1638  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1639  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1640  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1641  #endif
1642  #endif
1643  }
1644  else
1645  {
1646  //
1647  // We are accessing a data that is outside the stream buffer
1648  //
1649  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1650  }
1651  }
1652 
1653  return pHandle->errorCode;
1654 }
1655 
1664 {
1665  assert(pHandle);
1666 
1667  //
1668  // Test if we haven't already an error
1669  //
1670  if (pHandle->errorCode == SBG_NO_ERROR)
1671  {
1672  //
1673  // Test if we can access this item
1674  //
1675  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint64_t))
1676  {
1677  //
1678  // Test if the platform supports un-aligned access and if the endianness is the same
1679  //
1680  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1681  //
1682  // Write the value
1683  //
1684  *((uint64_t*)(pHandle->pCurrentPtr)) = value;
1685 
1686  //
1687  // Increment the current pointer
1688  //
1689  pHandle->pCurrentPtr += sizeof(uint64_t);
1690  #else
1691  //
1692  // Store data according to platform endianness
1693  //
1694  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1695  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1696  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1697  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1698  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1699  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1700  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1701  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1702  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1703  #else
1704  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1705  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1706  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1707  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1708  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1709  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1710  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1711  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1712  #endif
1713  #endif
1714  }
1715  else
1716  {
1717  //
1718  // We are accessing a data that is outside the stream buffer
1719  //
1720  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1721  }
1722  }
1723 
1724  return pHandle->errorCode;
1725 }
1726 
1735 {
1736  assert(pHandle);
1737 
1738  //
1739  // Make sure the provided size_t value doesn't exceed a uint32_t storage
1740  //
1741  assert(value <= UINT32_MAX);
1742 
1743  //
1744  // Call the write method to store a uint32_t
1745  //
1746  return sbgStreamBufferWriteUint32LE(pHandle, (uint32_t)value);
1747 }
1748 
1757 {
1758  assert(pHandle);
1759 
1760  //
1761  // Call the write method to store a uint64_t
1762  //
1763  return sbgStreamBufferWriteUint64LE(pHandle, (uint64_t)value);
1764 }
1765 
1774 {
1775  SbgFloatNint floatInt;
1776 
1777  assert(pHandle);
1778 
1779  //
1780  // Test if we haven't already an error
1781  //
1782  if (pHandle->errorCode == SBG_NO_ERROR)
1783  {
1784  //
1785  // We use an union to avoid compiler cast
1786  //
1787  floatInt.valF = value;
1788 
1789  //
1790  // Write this float as an uint32_t
1791  //
1792  return sbgStreamBufferWriteUint32LE(pHandle, floatInt.valU);
1793  }
1794 
1795  return pHandle->errorCode;
1796 }
1797 
1806 {
1807  SbgDoubleNint doubleInt;
1808 
1809  assert(pHandle);
1810 
1811  //
1812  // Test if we haven't already an error
1813  //
1814  if (pHandle->errorCode == SBG_NO_ERROR)
1815  {
1816  //
1817  // We use an union to avoid compiler cast
1818  //
1819  doubleInt.valF = value;
1820 
1821  //
1822  // Write this float as an uint64_t
1823  //
1824  return sbgStreamBufferWriteUint64LE(pHandle, doubleInt.valU);
1825  }
1826 
1827  return pHandle->errorCode;
1828 }
1829 
1839 SBG_INLINE SbgErrorCode sbgStreamBufferReadStringLE(SbgStreamBuffer *pHandle, char *pString, size_t maxSize)
1840 {
1841  size_t stringLength;
1842 
1843  assert(pHandle);
1844  assert(pString);
1845  assert(maxSize > 0);
1846 
1847  //
1848  // Test if we haven't already an error
1849  //
1850  if (pHandle->errorCode == SBG_NO_ERROR)
1851  {
1852  //
1853  // The C string are stored in a stream buffer with a 32 bit size length and then the buffer itself
1854  //
1855  stringLength = sbgStreamBufferReadSizeT32LE(pHandle);
1856 
1857  if (stringLength <= maxSize)
1858  {
1859  //
1860  // Read the string buffer itself
1861  //
1862  sbgStreamBufferReadBuffer(pHandle, pString, stringLength);
1863  }
1864  else
1865  {
1866  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1867  SBG_LOG_ERROR(pHandle->errorCode, "Trying to store a string of %zu bytes into a buffer of %zu bytes.", stringLength, maxSize);
1868  }
1869  }
1870 
1871  return pHandle->errorCode;
1872 }
1873 
1882 {
1883  size_t stringLength;
1884 
1885  assert(pHandle);
1886  assert(pString);
1887 
1888  //
1889  // Test if we haven't already an error
1890  //
1891  if (pHandle->errorCode == SBG_NO_ERROR)
1892  {
1893  //
1894  // We write C string using a 32 bit size_t as the string length including the NULL char
1895  // We should thus make sure the provided string isn't too big to fit in a 32 bits size_t
1896  //
1897  stringLength = strlen(pString) + 1;
1898 
1899  if (stringLength <= UINT32_MAX)
1900  {
1901  //
1902  // Write the string length
1903  //
1904  if (sbgStreamBufferWriteSizeT32LE(pHandle, stringLength) == SBG_NO_ERROR)
1905  {
1906  //
1907  // Write the string buffer itself
1908  //
1909  sbgStreamBufferWriteBuffer(pHandle, pString, stringLength);
1910  }
1911  }
1912  else
1913  {
1914  pHandle->errorCode = SBG_INVALID_PARAMETER;
1915  SBG_LOG_ERROR(pHandle->errorCode, "The provided string is too big to fit in a 32 bit size_t");
1916  }
1917  }
1918 
1919  return pHandle->errorCode;
1920 }
1921 
1922 #endif /* SBG_STREAM_BUFFER_LE_H */
#define SBG_INLINE
Definition: sbgDefines.h:227
enum _SbgErrorCode SbgErrorCode
@ SBG_BUFFER_OVERFLOW
Definition: sbgErrorCodes.h:59
@ SBG_NO_ERROR
Definition: sbgErrorCodes.h:48
@ SBG_INVALID_PARAMETER
Definition: sbgErrorCodes.h:60
Used to read/write data from/to a memory buffer stream.
SBG_INLINE SbgErrorCode sbgStreamBufferReadBuffer(SbgStreamBuffer *pHandle, void *pBuffer, size_t numBytesToRead)
Definition: sbgStreamBufferCommon.h:624
SBG_INLINE SbgErrorCode sbgStreamBufferWriteBuffer(SbgStreamBuffer *pHandle, const void *pBuffer, size_t numBytesToWrite)
Definition: sbgStreamBufferCommon.h:794
SBG_INLINE size_t sbgStreamBufferGetSpace(const SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferCommon.h:357
SBG_INLINE int64_t sbgStreamBufferReadUint40LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:530
SBG_INLINE double sbgStreamBufferReadDoubleLE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:1124
SBG_INLINE int64_t sbgStreamBufferReadInt48LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:600
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint24LE(SbgStreamBuffer *pHandle, uint32_t value)
Definition: sbgStreamBufferLE.h:1354
SBG_INLINE int64_t sbgStreamBufferReadInt40LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:460
SBG_INLINE uint16_t sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:117
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt64LE(SbgStreamBuffer *pHandle, int64_t value)
Definition: sbgStreamBufferLE.h:1592
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint64LE(SbgStreamBuffer *pHandle, uint64_t value)
Definition: sbgStreamBufferLE.h:1663
SBG_INLINE float sbgStreamBufferReadFloatLE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:1077
SBG_INLINE SbgErrorCode sbgStreamBufferWriteSizeT32LE(SbgStreamBuffer *pHandle, size_t value)
Definition: sbgStreamBufferLE.h:1734
SBG_INLINE uint64_t sbgStreamBufferReadUint48LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:672
SBG_INLINE uint64_t sbgStreamBufferReadUint56LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:818
SBG_INLINE uint32_t sbgStreamBufferReadUint24LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:252
SBG_INLINE uint32_t sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:389
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt24LE(SbgStreamBuffer *pHandle, int32_t value)
Definition: sbgStreamBufferLE.h:1295
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt32LE(SbgStreamBuffer *pHandle, int32_t value)
Definition: sbgStreamBufferLE.h:1413
SBG_INLINE int16_t sbgStreamBufferReadInt16LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:48
SBG_INLINE uint64_t sbgStreamBufferReadUint64LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:962
SBG_INLINE SbgErrorCode sbgStreamBufferWriteFloatLE(SbgStreamBuffer *pHandle, float value)
Definition: sbgStreamBufferLE.h:1773
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32_t value)
Definition: sbgStreamBufferLE.h:1476
SBG_INLINE SbgErrorCode sbgStreamBufferWriteDoubleLE(SbgStreamBuffer *pHandle, double value)
Definition: sbgStreamBufferLE.h:1805
SBG_INLINE size_t sbgStreamBufferReadSizeT32LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:1032
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint16LE(SbgStreamBuffer *pHandle, uint16_t value)
Definition: sbgStreamBufferLE.h:1235
SBG_INLINE size_t sbgStreamBufferReadSizeT64LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:1049
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint48LE(SbgStreamBuffer *pHandle, uint64_t value)
Definition: sbgStreamBufferLE.h:1539
SBG_INLINE int32_t sbgStreamBufferReadInt24LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:186
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt16LE(SbgStreamBuffer *pHandle, int16_t value)
Definition: sbgStreamBufferLE.h:1176
SBG_INLINE SbgErrorCode sbgStreamBufferWriteStringLE(SbgStreamBuffer *pHandle, const char *pString)
Definition: sbgStreamBufferLE.h:1881
SBG_INLINE SbgErrorCode sbgStreamBufferWriteSizeT64LE(SbgStreamBuffer *pHandle, size_t value)
Definition: sbgStreamBufferLE.h:1756
SBG_INLINE int64_t sbgStreamBufferReadInt56LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:744
SBG_INLINE int64_t sbgStreamBufferReadInt64LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:892
SBG_INLINE SbgErrorCode sbgStreamBufferReadStringLE(SbgStreamBuffer *pHandle, char *pString, size_t maxSize)
Definition: sbgStreamBufferLE.h:1839
SBG_INLINE int32_t sbgStreamBufferReadInt32LE(SbgStreamBuffer *pHandle)
Definition: sbgStreamBufferLE.h:318
Definition: sbgStreamBufferCommon.h:201
SbgErrorCode errorCode
Definition: sbgStreamBufferCommon.h:206
uint8_t * pCurrentPtr
Definition: sbgStreamBufferCommon.h:205
Definition: sbgTypes.h:149
Definition: sbgTypes.h:139
Definition: sbgTypes.h:103
Definition: sbgTypes.h:121
Definition: sbgTypes.h:112
Definition: sbgTypes.h:130