sbgStreamBufferLE.h
Go to the documentation of this file.
1 
21 #ifndef SBG_STREAM_BUFFER_LE_H
22 #define SBG_STREAM_BUFFER_LE_H
23 
24 #include "sbgStreamBufferCommon.h"
25 
26 //----------------------------------------------------------------------//
27 //- Read operations methods -//
28 //----------------------------------------------------------------------//
29 
36 {
37  int16_t bytesValues[2];
38 
39  //
40  // Check input parameters
41  //
42  assert(pHandle);
43 
44  //
45  // Test if we haven't already an error
46  //
47  if (pHandle->errorCode == SBG_NO_ERROR)
48  {
49  //
50  // Test if we can access this item
51  //
52  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int16_t))
53  {
54  //
55  // Test if the platform supports un-aligned access and if the endianness is the same
56  //
57  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
58  //
59  // Read the current value
60  //
61  bytesValues[0] = *((int16_t*)pHandle->pCurrentPtr);
62 
63  //
64  // Increment the current pointer
65  //
66  pHandle->pCurrentPtr += sizeof(int16_t);
67 
68  return bytesValues[0];
69  #else
70  //
71  // Read the each bytes
72  //
73  bytesValues[0] = *(pHandle->pCurrentPtr++);
74  bytesValues[1] = *(pHandle->pCurrentPtr++);
75 
76  //
77  // Store data according to platform endianness
78  //
79  #if (SBG_CONFIG_BIG_ENDIAN == 1)
80  return bytesValues[1] | (bytesValues[0] << 8);
81  #else
82  return bytesValues[0] | (bytesValues[1] << 8);
83  #endif
84  #endif
85  }
86  else
87  {
88  //
89  // We have a buffer overflow so return 0
90  //
91  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
92  }
93  }
94 
95  //
96  // If we are here, it means we have an error so return 0
97  //
98  return 0;
99 }
100 
107 {
108  uint16_t bytesValues[2];
109 
110  //
111  // Check input parameters
112  //
113  assert(pHandle);
114 
115  //
116  // Test if we haven't already an error
117  //
118  if (pHandle->errorCode == SBG_NO_ERROR)
119  {
120  //
121  // Test if we can access this item
122  //
123  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint16_t))
124  {
125  //
126  // Test if the platform supports un-aligned access and if the endianness is the same
127  //
128  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
129  //
130  // Read the current value
131  //
132  bytesValues[0] = *((uint16_t*)pHandle->pCurrentPtr);
133 
134  //
135  // Increment the current pointer
136  //
137  pHandle->pCurrentPtr += sizeof(uint16_t);
138 
139  return bytesValues[0];
140  #else
141  //
142  // Read the each bytes
143  //
144  bytesValues[0] = *(pHandle->pCurrentPtr++);
145  bytesValues[1] = *(pHandle->pCurrentPtr++);
146 
147  //
148  // Store data according to platform endianness
149  //
150  #if (SBG_CONFIG_BIG_ENDIAN == 1)
151  return bytesValues[1] | (bytesValues[0] << 8);
152  #else
153  return bytesValues[0] | (bytesValues[1] << 8);
154  #endif
155  #endif
156  }
157  else
158  {
159  //
160  // We have a buffer overflow so return 0
161  //
162  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
163  }
164  }
165 
166  //
167  // If we are here, it means we have an error so return 0
168  //
169  return 0;
170 }
171 
178 {
179  Uint8ToInt32 value;
180 
181  //
182  // Check input parameters
183  //
184  assert(pHandle);
185 
186  //
187  // Test if we haven't already an error
188  //
189  if (pHandle->errorCode == SBG_NO_ERROR)
190  {
191  //
192  // Test if we can access this item
193  //
194  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(uint8_t))
195  {
196  //
197  // Make sure the value is zero init
198  //
199  value.value = 0;
200 
201  //
202  // Store data according to platform endianness
203  //
204  #if (SBG_CONFIG_BIG_ENDIAN == 1)
205  //
206  // Read the each bytes
207  //
208  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
209  value.buffer[1] = *(pHandle->pCurrentPtr++);
210  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
211  #else
212  //
213  // Read the each bytes
214  //
215  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
216  value.buffer[2] = *(pHandle->pCurrentPtr++);
217  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
218  #endif
219 
220  //
221  // Shift the value to handle the sign correctly for a 24 bits
222  //
223  return value.value >> (32-24);
224  }
225  else
226  {
227  //
228  // We have a buffer overflow so return 0
229  //
230  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
231  }
232  }
233 
234  //
235  // If we are here, it means we have an error so return 0
236  //
237  return 0;
238 }
239 
246 {
247  Uint8ToUint32 value;
248 
249  //
250  // Check input parameters
251  //
252  assert(pHandle);
253 
254  //
255  // Test if we haven't already an error
256  //
257  if (pHandle->errorCode == SBG_NO_ERROR)
258  {
259  //
260  // Test if we can access this item
261  //
262  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(uint8_t))
263  {
264  //
265  // Make sure the value is zero init
266  //
267  value.value = 0;
268 
269  //
270  // Store data according to platform endianness
271  //
272  #if (SBG_CONFIG_BIG_ENDIAN == 1)
273  //
274  // Read the each bytes
275  //
276  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
277  value.buffer[1] = *(pHandle->pCurrentPtr++);
278  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
279  #else
280  //
281  // Read the each bytes
282  //
283  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
284  value.buffer[2] = *(pHandle->pCurrentPtr++);
285  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
286  #endif
287 
288  //
289  // Shift the value to handle the sign correctly for a 24 bits
290  //
291  return value.value >> (32-24);
292  }
293  else
294  {
295  //
296  // We have a buffer overflow so return 0
297  //
298  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
299  }
300  }
301 
302  //
303  // If we are here, it means we have an error so return 0
304  //
305  return 0;
306 }
307 
314 {
315  int32_t bytesValues[4];
316 
317  //
318  // Check input parameters
319  //
320  assert(pHandle);
321 
322  //
323  // Test if we haven't already an error
324  //
325  if (pHandle->errorCode == SBG_NO_ERROR)
326  {
327  //
328  // Test if we can access this item
329  //
330  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int32_t))
331  {
332  //
333  // Test if the platform supports un-aligned access and if the endianness is the same
334  //
335  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
336  //
337  // Read the current value
338  //
339  bytesValues[0] = *((int32_t*)pHandle->pCurrentPtr);
340 
341  //
342  // Increment the current pointer
343  //
344  pHandle->pCurrentPtr += sizeof(int32_t);
345 
346  return bytesValues[0];
347  #else
348  //
349  // Read the each bytes
350  //
351  bytesValues[0] = *(pHandle->pCurrentPtr++);
352  bytesValues[1] = *(pHandle->pCurrentPtr++);
353  bytesValues[2] = *(pHandle->pCurrentPtr++);
354  bytesValues[3] = *(pHandle->pCurrentPtr++);
355 
356  //
357  // Store data according to platform endianness
358  //
359  #if (SBG_CONFIG_BIG_ENDIAN == 1)
360  return bytesValues[3] | (bytesValues[2] << 8) | (bytesValues[1] << 16) | (bytesValues[0] << 24);
361  #else
362  return bytesValues[0] | (bytesValues[1] << 8) | (bytesValues[2] << 16) | (bytesValues[3] << 24);
363  #endif
364  #endif
365  }
366  else
367  {
368  //
369  // We have a buffer overflow so return 0
370  //
371  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
372  }
373  }
374 
375  //
376  // If we are here, it means we have an error so return 0
377  //
378  return 0;
379 }
380 
387 {
388  uint32_t bytesValues[4];
389 
390  //
391  // Check input parameters
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 
460 {
461  Uint8ToInt64 value;
462 
463  //
464  // Check input parameters
465  //
466  assert(pHandle);
467 
468  //
469  // Test if we haven't already an error
470  //
471  if (pHandle->errorCode == SBG_NO_ERROR)
472  {
473  //
474  // Test if we can access this item
475  //
476  if (sbgStreamBufferGetSpace(pHandle) >= 5*sizeof(uint8_t))
477  {
478  //
479  // Make sure the value is zero init
480  //
481  value.value = 0;
482 
483  //
484  // Store data according to platform endianness
485  //
486  #if (SBG_CONFIG_BIG_ENDIAN == 1)
487  //
488  // Read the each bytes
489  //
490  value.buffer[4] = *(pHandle->pCurrentPtr++); // LSB
491  value.buffer[3] = *(pHandle->pCurrentPtr++);
492  value.buffer[2] = *(pHandle->pCurrentPtr++);
493  value.buffer[1] = *(pHandle->pCurrentPtr++);
494  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
495  #else
496  //
497  // Read the each bytes
498  //
499  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
500  value.buffer[4] = *(pHandle->pCurrentPtr++);
501  value.buffer[5] = *(pHandle->pCurrentPtr++);
502  value.buffer[6] = *(pHandle->pCurrentPtr++);
503  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
504  #endif
505 
506  //
507  // Shift the value to handle the sign correctly for a 40 bits
508  //
509  return value.value >> (64-40);
510  }
511  else
512  {
513  //
514  // We have a buffer overflow so return 0
515  //
516  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
517  }
518  }
519 
520  //
521  // If we are here, it means we have an error so return 0
522  //
523  return 0;
524 }
525 
532 {
533  Uint8ToUint64 value;
534 
535  //
536  // Check input parameters
537  //
538  assert(pHandle);
539 
540  //
541  // Test if we haven't already an error
542  //
543  if (pHandle->errorCode == SBG_NO_ERROR)
544  {
545  //
546  // Test if we can access this item
547  //
548  if (sbgStreamBufferGetSpace(pHandle) >= 5*sizeof(uint8_t))
549  {
550  //
551  // Make sure the value is zero init
552  //
553  value.value = 0;
554 
555  //
556  // Store data according to platform endianness
557  //
558  #if (SBG_CONFIG_BIG_ENDIAN == 1)
559  //
560  // Read the each bytes
561  //
562  value.buffer[4] = *(pHandle->pCurrentPtr++); // LSB
563  value.buffer[3] = *(pHandle->pCurrentPtr++);
564  value.buffer[2] = *(pHandle->pCurrentPtr++);
565  value.buffer[1] = *(pHandle->pCurrentPtr++);
566  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
567  #else
568  //
569  // Read the each bytes
570  //
571  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
572  value.buffer[4] = *(pHandle->pCurrentPtr++);
573  value.buffer[5] = *(pHandle->pCurrentPtr++);
574  value.buffer[6] = *(pHandle->pCurrentPtr++);
575  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
576  #endif
577 
578  //
579  // Shift the value to handle the sign correctly for a 40 bits
580  //
581  return value.value >> (64-40);
582  }
583  else
584  {
585  //
586  // We have a buffer overflow so return 0
587  //
588  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
589  }
590  }
591 
592  //
593  // If we are here, it means we have an error so return 0
594  //
595  return 0;
596 }
597 
604 {
605  Uint8ToInt64 value;
606 
607  //
608  // Check input parameters
609  //
610  assert(pHandle);
611 
612  //
613  // Test if we haven't already an error
614  //
615  if (pHandle->errorCode == SBG_NO_ERROR)
616  {
617  //
618  // Test if we can access this item
619  //
620  if (sbgStreamBufferGetSpace(pHandle) >= 6*sizeof(uint8_t))
621  {
622  //
623  // Make sure the value is zero init
624  //
625  value.value = 0;
626 
627  //
628  // Store data according to platform endianness
629  //
630  #if (SBG_CONFIG_BIG_ENDIAN == 1)
631  //
632  // Read the each bytes
633  //
634  value.buffer[5] = *(pHandle->pCurrentPtr++); // LSB
635  value.buffer[4] = *(pHandle->pCurrentPtr++);
636  value.buffer[3] = *(pHandle->pCurrentPtr++);
637  value.buffer[2] = *(pHandle->pCurrentPtr++);
638  value.buffer[1] = *(pHandle->pCurrentPtr++);
639  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
640  #else
641  //
642  // Read the each bytes
643  //
644  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
645  value.buffer[3] = *(pHandle->pCurrentPtr++);
646  value.buffer[4] = *(pHandle->pCurrentPtr++);
647  value.buffer[5] = *(pHandle->pCurrentPtr++);
648  value.buffer[6] = *(pHandle->pCurrentPtr++);
649  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
650  #endif
651 
652  //
653  // Shift the value to handle the sign correctly for a 48 bits
654  //
655  return value.value >> (64-48);
656  }
657  else
658  {
659  //
660  // We have a buffer overflow so return 0
661  //
662  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
663  }
664  }
665 
666  //
667  // If we are here, it means we have an error so return 0
668  //
669  return 0;
670 }
671 
678 {
679  Uint8ToUint64 value;
680 
681  //
682  // Check input parameters
683  //
684  assert(pHandle);
685 
686  //
687  // Test if we haven't already an error
688  //
689  if (pHandle->errorCode == SBG_NO_ERROR)
690  {
691  //
692  // Test if we can access this item
693  //
694  if (sbgStreamBufferGetSpace(pHandle) >= 6*sizeof(uint8_t))
695  {
696  //
697  // Make sure the value is zero init
698  //
699  value.value = 0;
700 
701  //
702  // Store data according to platform endianness
703  //
704  #if (SBG_CONFIG_BIG_ENDIAN == 1)
705  //
706  // Read the each bytes
707  //
708  value.buffer[5] = *(pHandle->pCurrentPtr++); // LSB
709  value.buffer[4] = *(pHandle->pCurrentPtr++);
710  value.buffer[3] = *(pHandle->pCurrentPtr++);
711  value.buffer[2] = *(pHandle->pCurrentPtr++);
712  value.buffer[1] = *(pHandle->pCurrentPtr++);
713  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
714  #else
715  //
716  // Read the each bytes
717  //
718  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
719  value.buffer[3] = *(pHandle->pCurrentPtr++);
720  value.buffer[4] = *(pHandle->pCurrentPtr++);
721  value.buffer[5] = *(pHandle->pCurrentPtr++);
722  value.buffer[6] = *(pHandle->pCurrentPtr++);
723  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
724  #endif
725 
726  //
727  // Shift the value to handle the sign correctly for a 48 bits
728  //
729  return value.value >> (64-48);
730  }
731  else
732  {
733  //
734  // We have a buffer overflow so return 0
735  //
736  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
737  }
738  }
739 
740  //
741  // If we are here, it means we have an error so return 0
742  //
743  return 0;
744 }
745 
752 {
753  Uint8ToInt64 value;
754 
755  //
756  // Check input parameters
757  //
758  assert(pHandle);
759 
760  //
761  // Test if we haven't already an error
762  //
763  if (pHandle->errorCode == SBG_NO_ERROR)
764  {
765  //
766  // Test if we can access this item
767  //
768  if (sbgStreamBufferGetSpace(pHandle) >= 7*sizeof(uint8_t))
769  {
770  //
771  // Make sure the value is zero init
772  //
773  value.value = 0;
774 
775  //
776  // Store data according to platform endianness
777  //
778  #if (SBG_CONFIG_BIG_ENDIAN == 1)
779  //
780  // Read the each bytes
781  //
782  value.buffer[6] = *(pHandle->pCurrentPtr++); // LSB
783  value.buffer[5] = *(pHandle->pCurrentPtr++);
784  value.buffer[4] = *(pHandle->pCurrentPtr++);
785  value.buffer[3] = *(pHandle->pCurrentPtr++);
786  value.buffer[2] = *(pHandle->pCurrentPtr++);
787  value.buffer[1] = *(pHandle->pCurrentPtr++);
788  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
789  #else
790  //
791  // Read the each bytes
792  //
793  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
794  value.buffer[2] = *(pHandle->pCurrentPtr++);
795  value.buffer[3] = *(pHandle->pCurrentPtr++);
796  value.buffer[4] = *(pHandle->pCurrentPtr++);
797  value.buffer[5] = *(pHandle->pCurrentPtr++);
798  value.buffer[6] = *(pHandle->pCurrentPtr++);
799  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
800  #endif
801 
802  //
803  // Shift the value to handle the sign correctly for a 56 bits
804  //
805  return value.value >> (64-56);
806  }
807  else
808  {
809  //
810  // We have a buffer overflow so return 0
811  //
812  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
813  }
814  }
815 
816  //
817  // If we are here, it means we have an error so return 0
818  //
819  return 0;
820 }
821 
828 {
829  Uint8ToUint64 value;
830 
831  //
832  // Check input parameters
833  //
834  assert(pHandle);
835 
836  //
837  // Test if we haven't already an error
838  //
839  if (pHandle->errorCode == SBG_NO_ERROR)
840  {
841  //
842  // Test if we can access this item
843  //
844  if (sbgStreamBufferGetSpace(pHandle) >= 7*sizeof(uint8_t))
845  {
846  //
847  // Make sure the value is zero init
848  //
849  value.value = 0;
850 
851  //
852  // Store data according to platform endianness
853  //
854  #if (SBG_CONFIG_BIG_ENDIAN == 1)
855  //
856  // Read the each bytes
857  //
858  value.buffer[6] = *(pHandle->pCurrentPtr++); // LSB
859  value.buffer[5] = *(pHandle->pCurrentPtr++);
860  value.buffer[4] = *(pHandle->pCurrentPtr++);
861  value.buffer[3] = *(pHandle->pCurrentPtr++);
862  value.buffer[2] = *(pHandle->pCurrentPtr++);
863  value.buffer[1] = *(pHandle->pCurrentPtr++);
864  value.buffer[0] = *(pHandle->pCurrentPtr++); // MSB
865  #else
866  //
867  // Read the each bytes
868  //
869  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
870  value.buffer[2] = *(pHandle->pCurrentPtr++);
871  value.buffer[3] = *(pHandle->pCurrentPtr++);
872  value.buffer[4] = *(pHandle->pCurrentPtr++);
873  value.buffer[5] = *(pHandle->pCurrentPtr++);
874  value.buffer[6] = *(pHandle->pCurrentPtr++);
875  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
876  #endif
877 
878  //
879  // Shift the value to handle the sign correctly for a 56 bits
880  //
881  return value.value >> (64-56);
882  }
883  else
884  {
885  //
886  // We have a buffer overflow so return 0
887  //
888  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
889  }
890  }
891 
892  //
893  // If we are here, it means we have an error so return 0
894  //
895  return 0;
896 }
897 
904 {
905  int64_t lowPart;
906  int64_t highPart;
907 
908  //
909  // Check input parameters
910  //
911  assert(pHandle);
912 
913  //
914  // Test if we haven't already an error
915  //
916  if (pHandle->errorCode == SBG_NO_ERROR)
917  {
918  //
919  // Test if we can access this item
920  //
921  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int64_t))
922  {
923  //
924  // Test if the platform supports un-aligned access and if the endianness is the same
925  //
926  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
927  //
928  // Read the current value
929  //
930  lowPart = *((int64_t*)pHandle->pCurrentPtr);
931 
932  //
933  // Increment the current pointer
934  //
935  pHandle->pCurrentPtr += sizeof(int64_t);
936 
937  return lowPart;
938  #else
939  //
940  // Read 64 bit value using two 32 bits read to avoid too much 64 bits operations
941  //
942  lowPart = sbgStreamBufferReadUint32LE(pHandle);
943  highPart = sbgStreamBufferReadUint32LE(pHandle);
944 
945  //
946  // Store data according to platform endianness
947  //
948  #if (SBG_CONFIG_BIG_ENDIAN == 1)
949  return (lowPart << 32) | highPart;
950  #else
951  return lowPart | (highPart << 32);
952  #endif
953  #endif
954  }
955  else
956  {
957  //
958  // We have a buffer overflow so return 0
959  //
960  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
961  }
962  }
963 
964  //
965  // If we are here, it means we have an error so return 0
966  //
967  return 0ll;
968 }
969 
976 {
977  uint64_t lowPart;
978  uint64_t highPart;
979 
980  //
981  // Check input parameters
982  //
983  assert(pHandle);
984 
985  //
986  // Test if we haven't already an error
987  //
988  if (pHandle->errorCode == SBG_NO_ERROR)
989  {
990  //
991  // Test if we can access this item
992  //
993  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint64_t))
994  {
995  //
996  // Test if the platform supports un-aligned access and if the endianness is the same
997  //
998  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
999  //
1000  // Read the current value
1001  //
1002  lowPart = *((uint64_t*)pHandle->pCurrentPtr);
1003 
1004  //
1005  // Increment the current pointer
1006  //
1007  pHandle->pCurrentPtr += sizeof(uint64_t);
1008 
1009  return lowPart;
1010  #else
1011  //
1012  // Read 64 bit value using two 32 bits read to avoid too much 64 bits operations
1013  //
1014  lowPart = sbgStreamBufferReadUint32LE(pHandle);
1015  highPart = sbgStreamBufferReadUint32LE(pHandle);
1016 
1017  //
1018  // Store data according to platform endianness
1019  //
1020  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1021  return (lowPart << 32) | highPart;
1022  #else
1023  return lowPart | (highPart << 32);
1024  #endif
1025  #endif
1026  }
1027  else
1028  {
1029  //
1030  // We have a buffer overflow so return 0
1031  //
1032  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1033  }
1034  }
1035 
1036  //
1037  // If we are here, it means we have an error so return 0
1038  //
1039  return 0ull;
1040 }
1041 
1048 {
1049  //
1050  // Just call the read method for uint32_t
1051  // We assume that a size_t is at least 32 bits on all platforms
1052  //
1053  return (size_t)sbgStreamBufferReadUint32LE(pHandle);
1054 }
1055 
1062 {
1063  uint64_t size;
1064 
1065  //
1066  // Just call the read method for uint64_t
1067  //
1068  size = sbgStreamBufferReadUint64LE(pHandle);
1069 
1070  //
1071  // Make sure the read size can fit in the size_t in size_t is 32 bits
1072  //
1073  assert((sizeof(size_t) == 8) || ((sizeof(size_t) == 4) && (size <= UINT32_MAX)));
1074 
1075  //
1076  // Return the read value
1077  //
1078  return (size_t)size;
1079 }
1080 
1087 {
1088  FloatNint floatInt;
1089 
1090  //
1091  // Check input parameters
1092  //
1093  assert(pHandle);
1094 
1095  //
1096  // Test if we haven't already an error
1097  //
1098  if (pHandle->errorCode == SBG_NO_ERROR)
1099  {
1100  //
1101  // Test if we can access this item
1102  //
1103  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(float))
1104  {
1105  //
1106  // Read the float as an uint32_t
1107  //
1108  floatInt.valU = sbgStreamBufferReadUint32LE(pHandle);
1109 
1110  //
1111  // Return the float using an union to avoid compiler cast
1112  //
1113  return floatInt.valF;
1114  }
1115  else
1116  {
1117  //
1118  // We have a buffer overflow so return 0
1119  //
1120  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1121  }
1122  }
1123 
1124  //
1125  // If we are here, it means we have an error so return 0
1126  //
1127  return 0.0f;
1128 }
1129 
1136 {
1137  DoubleNint doubleInt;
1138 
1139  //
1140  // Check input parameters
1141  //
1142  assert(pHandle);
1143 
1144  //
1145  // Test if we haven't already an error
1146  //
1147  if (pHandle->errorCode == SBG_NO_ERROR)
1148  {
1149  //
1150  // Test if we can access this item
1151  //
1152  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(double))
1153  {
1154  //
1155  // Read the float as an uint64_t
1156  //
1157  doubleInt.valU = sbgStreamBufferReadUint64LE(pHandle);
1158 
1159  //
1160  // Return the double using an union to avoid compiler cast
1161  //
1162  return doubleInt.valF;
1163  }
1164  else
1165  {
1166  //
1167  // We have a buffer overflow so return 0
1168  //
1169  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1170  }
1171  }
1172 
1173  //
1174  // If we are here, it means we have an error so return 0
1175  //
1176  return 0.0;
1177 }
1178 
1179 //----------------------------------------------------------------------//
1180 //- Write operations methods -//
1181 //----------------------------------------------------------------------//
1182 
1190 {
1191  //
1192  // Check input parameters
1193  //
1194  assert(pHandle);
1195 
1196  //
1197  // Test if we haven't already an error
1198  //
1199  if (pHandle->errorCode == SBG_NO_ERROR)
1200  {
1201  //
1202  // Test if we can access this item
1203  //
1204  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int16_t))
1205  {
1206  //
1207  // Test if the platform supports un-aligned access and if the endianness is the same
1208  //
1209  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1210  //
1211  // Write the value
1212  //
1213  *((int16_t*)(pHandle->pCurrentPtr)) = value;
1214 
1215  //
1216  // Increment the current pointer
1217  //
1218  pHandle->pCurrentPtr += sizeof(int16_t);
1219  #else
1220  //
1221  // Store data according to platform endianness
1222  //
1223  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1224  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1225  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1226  #else
1227  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1228  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1229  #endif
1230  #endif
1231  }
1232  else
1233  {
1234  //
1235  // We are accessing a data that is outside the stream buffer
1236  //
1237  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1238  }
1239  }
1240 
1241  return pHandle->errorCode;
1242 }
1243 
1251 {
1252  //
1253  // Check input parameters
1254  //
1255  assert(pHandle);
1256 
1257  //
1258  // Test if we haven't already an error
1259  //
1260  if (pHandle->errorCode == SBG_NO_ERROR)
1261  {
1262  //
1263  // Test if we can access this item
1264  //
1265  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint16_t))
1266  {
1267  //
1268  // Test if the platform supports un-aligned access and if the endianness is the same
1269  //
1270  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1271  //
1272  // Write the value
1273  //
1274  *((uint16_t*)(pHandle->pCurrentPtr)) = value;
1275 
1276  //
1277  // Increment the current pointer
1278  //
1279  pHandle->pCurrentPtr += sizeof(uint16_t);
1280  #else
1281  //
1282  // Store data according to platform endianness
1283  //
1284  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1285  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1286  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1287  #else
1288  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1289  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1290  #endif
1291  #endif
1292  }
1293  else
1294  {
1295  //
1296  // We are accessing a data that is outside the stream buffer
1297  //
1298  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1299  }
1300  }
1301 
1302  return pHandle->errorCode;
1303 }
1304 
1305 
1313 {
1314  //
1315  // Check input parameters
1316  //
1317  assert(pHandle);
1318 
1319  //
1320  // Test if we haven't already an error
1321  //
1322  if (pHandle->errorCode == SBG_NO_ERROR)
1323  {
1324  //
1325  // Make sure that the value is within 24 bit bonds
1326  //
1327  if ( (value >= SBG_MIN_INT_24) && (value <= SBG_MAX_INT_24) )
1328  {
1329  //
1330  // Test if we can access this item
1331  //
1332  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(int8_t))
1333  {
1334  //
1335  // Store data according to platform endianness
1336  //
1337  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1338  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1339  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1340  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1341  #else
1342  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1343  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1344  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1345  #endif
1346  }
1347  else
1348  {
1349  //
1350  // We are accessing a data that is outside the stream buffer
1351  //
1352  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1353  }
1354  }
1355  else
1356  {
1357  //
1358  // The input value is not within a 24 bit integer bounds
1359  //
1360  pHandle->errorCode = SBG_INVALID_PARAMETER;
1361  }
1362  }
1363 
1364  return pHandle->errorCode;
1365 }
1366 
1374 {
1375  //
1376  // Check input parameters
1377  //
1378  assert(pHandle);
1379 
1380  //
1381  // Test if we haven't already an error
1382  //
1383  if (pHandle->errorCode == SBG_NO_ERROR)
1384  {
1385  //
1386  // Make sure that the value is within 24 bit bonds
1387  //
1388  if (value <= SBG_MAX_UINT_24)
1389  {
1390  //
1391  // Test if we can access this item
1392  //
1393  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(uint8_t))
1394  {
1395  //
1396  // Store data according to platform endianness
1397  //
1398  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1399  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1400  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1401  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1402  #else
1403  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1404  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1405  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1406  #endif
1407  }
1408  else
1409  {
1410  //
1411  // We are accessing a data that is outside the stream buffer
1412  //
1413  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1414  }
1415  }
1416  else
1417  {
1418  //
1419  // The input value is not within a 24 bit integer bounds
1420  //
1421  pHandle->errorCode = SBG_INVALID_PARAMETER;
1422  }
1423  }
1424 
1425  return pHandle->errorCode;
1426 }
1427 
1435 {
1436  //
1437  // Check input parameters
1438  //
1439  assert(pHandle);
1440 
1441  //
1442  // Test if we haven't already an error
1443  //
1444  if (pHandle->errorCode == SBG_NO_ERROR)
1445  {
1446  //
1447  // Test if we can access this item
1448  //
1449  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int32_t))
1450  {
1451  //
1452  // Test if the platform supports un-aligned access and if the endianness is the same
1453  //
1454  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1455  //
1456  // Write the value
1457  //
1458  *((int32_t*)(pHandle->pCurrentPtr)) = value;
1459 
1460  //
1461  // Increment the current pointer
1462  //
1463  pHandle->pCurrentPtr += sizeof(int32_t);
1464  #else
1465  //
1466  // Store data according to platform endianness
1467  //
1468  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1469  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1470  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1471  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1472  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1473  #else
1474  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1475  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1476  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1477  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1478  #endif
1479  #endif
1480  }
1481  else
1482  {
1483  //
1484  // We are accessing a data that is outside the stream buffer
1485  //
1486  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1487  }
1488  }
1489 
1490  return pHandle->errorCode;
1491 }
1492 
1500 {
1501  //
1502  // Check input parameters
1503  //
1504  assert(pHandle);
1505 
1506  //
1507  // Test if we haven't already an error
1508  //
1509  if (pHandle->errorCode == SBG_NO_ERROR)
1510  {
1511  //
1512  // Test if we can access this item
1513  //
1514  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint32_t))
1515  {
1516  //
1517  // Test if the platform supports un-aligned access and if the endianness is the same
1518  //
1519  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1520  //
1521  // Write the value
1522  //
1523  *((uint32_t*)(pHandle->pCurrentPtr)) = value;
1524 
1525  //
1526  // Increment the current pointer
1527  //
1528  pHandle->pCurrentPtr += sizeof(uint32_t);
1529  #else
1530  //
1531  // Store data according to platform endianness
1532  //
1533  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1534  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1535  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1536  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1537  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1538  #else
1539  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1540  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1541  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1542  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1543  #endif
1544  #endif
1545  }
1546  else
1547  {
1548  //
1549  // We are accessing a data that is outside the stream buffer
1550  //
1551  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1552  }
1553  }
1554 
1555  return pHandle->errorCode;
1556 }
1557 
1565 {
1566  //
1567  // Check input parameters
1568  //
1569  assert(pHandle);
1570 
1571  //
1572  // Test if we haven't already an error
1573  //
1574  if (pHandle->errorCode == SBG_NO_ERROR)
1575  {
1576  //
1577  // Test if we can access this item
1578  //
1579  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int64_t))
1580  {
1581  //
1582  // Test if the platform supports un-aligned access and if the endianness is the same
1583  //
1584  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1585  //
1586  // Write the value
1587  //
1588  *((int64_t*)(pHandle->pCurrentPtr)) = value;
1589 
1590  //
1591  // Increment the current pointer
1592  //
1593  pHandle->pCurrentPtr += sizeof(int64_t);
1594  #else
1595  //
1596  // Store data according to platform endianness
1597  //
1598  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1599  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1600  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1601  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1602  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1603  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1604  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1605  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1606  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1607  #else
1608  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1609  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1610  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1611  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1612  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1613  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1614  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1615  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1616  #endif
1617  #endif
1618  }
1619  else
1620  {
1621  //
1622  // We are accessing a data that is outside the stream buffer
1623  //
1624  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1625  }
1626  }
1627 
1628  return pHandle->errorCode;
1629 }
1630 
1638 {
1639  //
1640  // Check input parameters
1641  //
1642  assert(pHandle);
1643 
1644  //
1645  // Test if we haven't already an error
1646  //
1647  if (pHandle->errorCode == SBG_NO_ERROR)
1648  {
1649  //
1650  // Test if we can access this item
1651  //
1652  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint64_t))
1653  {
1654  //
1655  // Test if the platform supports un-aligned access and if the endianness is the same
1656  //
1657  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 0)
1658  //
1659  // Write the value
1660  //
1661  *((uint64_t*)(pHandle->pCurrentPtr)) = value;
1662 
1663  //
1664  // Increment the current pointer
1665  //
1666  pHandle->pCurrentPtr += sizeof(uint64_t);
1667  #else
1668  //
1669  // Store data according to platform endianness
1670  //
1671  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1672  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1673  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1674  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1675  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1676  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1677  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1678  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1679  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1680  #else
1681  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1682  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1683  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1684  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1685  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1686  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1687  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1688  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1689  #endif
1690  #endif
1691  }
1692  else
1693  {
1694  //
1695  // We are accessing a data that is outside the stream buffer
1696  //
1697  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1698  }
1699  }
1700 
1701  return pHandle->errorCode;
1702 }
1703 
1711 {
1712  //
1713  // Check input parameters
1714  //
1715  assert(pHandle);
1716 
1717  //
1718  // Make sure the provided size_t value doesn't exceed a uint32_t storage
1719  //
1720  assert(value <= UINT32_MAX);
1721 
1722  //
1723  // Call the write method to store a uint32_t
1724  //
1725  return sbgStreamBufferWriteUint32LE(pHandle, (uint32_t)value);
1726 }
1727 
1735 {
1736  //
1737  // Check input parameters
1738  //
1739  assert(pHandle);
1740 
1741  //
1742  // Call the write method to store a uint64_t
1743  //
1744  return sbgStreamBufferWriteUint64LE(pHandle, (uint64_t)value);
1745 }
1746 
1754 {
1755  FloatNint floatInt;
1756 
1757  //
1758  // Check input parameters
1759  //
1760  assert(pHandle);
1761 
1762  //
1763  // Test if we haven't already an error
1764  //
1765  if (pHandle->errorCode == SBG_NO_ERROR)
1766  {
1767  //
1768  // We use an union to avoid compiler cast
1769  //
1770  floatInt.valF = value;
1771 
1772  //
1773  // Write this float as an uint32_t
1774  //
1775  return sbgStreamBufferWriteUint32LE(pHandle, floatInt.valU);
1776  }
1777 
1778  return pHandle->errorCode;
1779 }
1780 
1788 {
1789  DoubleNint doubleInt;
1790 
1791  //
1792  // Check input parameters
1793  //
1794  assert(pHandle);
1795 
1796  //
1797  // Test if we haven't already an error
1798  //
1799  if (pHandle->errorCode == SBG_NO_ERROR)
1800  {
1801  //
1802  // We use an union to avoid compiler cast
1803  //
1804  doubleInt.valF = value;
1805 
1806  //
1807  // Write this float as an uint64_t
1808  //
1809  return sbgStreamBufferWriteUint64LE(pHandle, doubleInt.valU);
1810  }
1811 
1812  return pHandle->errorCode;
1813 }
1814 
1824 SBG_INLINE SbgErrorCode sbgStreamBufferReadStringLE(SbgStreamBuffer *pHandle, char *pString, size_t maxSize)
1825 {
1826  size_t stringLength;
1827 
1828  //
1829  // Check input parameters
1830  //
1831  assert(pHandle);
1832  assert(pString);
1833  assert(maxSize > 0);
1834 
1835  //
1836  // Test if we haven't already an error
1837  //
1838  if (pHandle->errorCode == SBG_NO_ERROR)
1839  {
1840  //
1841  // The C string are stored in a stream buffer with a 32 bit size length and then the buffer itself
1842  //
1843  stringLength = sbgStreamBufferReadSizeT32LE(pHandle);
1844 
1845  if (stringLength <= maxSize)
1846  {
1847  //
1848  // Read the string buffer itself
1849  //
1850  sbgStreamBufferReadBuffer(pHandle, pString, stringLength);
1851  }
1852  else
1853  {
1854  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1855  SBG_LOG_ERROR(pHandle->errorCode, "Trying to store a string of %u bytes into a buffer of %u bytes.", stringLength, maxSize);
1856  }
1857  }
1858 
1859  return pHandle->errorCode;
1860 }
1861 
1869 {
1870  size_t stringLength;
1871 
1872  //
1873  // Check input parameters
1874  //
1875  assert(pHandle);
1876  assert(pString);
1877 
1878  //
1879  // Test if we haven't already an error
1880  //
1881  if (pHandle->errorCode == SBG_NO_ERROR)
1882  {
1883  //
1884  // We write C string using a 32 bit size_t as the string length including the NULL char
1885  // We should thus make sure the provided string isn't too big to fit in a 32 bits size_t
1886  //
1887  stringLength = strlen(pString) + 1;
1888 
1889  if (stringLength <= UINT32_MAX)
1890  {
1891  //
1892  // Write the string length
1893  //
1894  if (sbgStreamBufferWriteSizeT32LE(pHandle, stringLength) == SBG_NO_ERROR)
1895  {
1896  //
1897  // Write the string buffer itself
1898  //
1899  sbgStreamBufferWriteBuffer(pHandle, pString, stringLength);
1900  }
1901  }
1902  else
1903  {
1904  pHandle->errorCode = SBG_INVALID_PARAMETER;
1905  SBG_LOG_ERROR(pHandle->errorCode, "The provided string is too big to fit in a 32 bit size_t");
1906  }
1907  }
1908 
1909  return pHandle->errorCode;
1910 }
1911 
1912 #endif /* SBG_STREAM_BUFFER_LE_H */
uint8_t buffer[8]
Definition: sbgTypes.h:121
double valF
Definition: sbgTypes.h:148
SBG_INLINE size_t sbgStreamBufferReadSizeT32LE(SbgStreamBuffer *pHandle)
#define SBG_MAX_UINT_24
Definition: sbgTypes.h:33
SBG_INLINE float sbgStreamBufferReadFloatLE(SbgStreamBuffer *pHandle)
SBG_INLINE uint32_t sbgStreamBufferReadUint24LE(SbgStreamBuffer *pHandle)
Used to read/write data from/to a memory buffer stream.
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt16LE(SbgStreamBuffer *pHandle, int16_t value)
SBG_INLINE int64_t sbgStreamBufferReadInt64LE(SbgStreamBuffer *pHandle)
SBG_INLINE int64_t sbgStreamBufferReadInt48LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteSizeT32LE(SbgStreamBuffer *pHandle, size_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteDoubleLE(SbgStreamBuffer *pHandle, double value)
SBG_INLINE int64_t sbgStreamBufferReadInt40LE(SbgStreamBuffer *pHandle)
int64_t value
Definition: sbgTypes.h:120
SBG_INLINE uint64_t sbgStreamBufferReadUint56LE(SbgStreamBuffer *pHandle)
uint64_t valU
Definition: sbgTypes.h:149
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt64LE(SbgStreamBuffer *pHandle, int64_t value)
SBG_INLINE uint16_t sbgStreamBufferReadUint16LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteSizeT64LE(SbgStreamBuffer *pHandle, size_t value)
SBG_INLINE int64_t sbgStreamBufferReadUint40LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint24LE(SbgStreamBuffer *pHandle, uint32_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint64LE(SbgStreamBuffer *pHandle, uint64_t value)
SBG_INLINE int32_t sbgStreamBufferReadInt24LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferReadBuffer(SbgStreamBuffer *pHandle, void *pBuffer, size_t numBytesToRead)
#define SBG_MAX_INT_24
Definition: sbgTypes.h:32
float valF
Definition: sbgTypes.h:138
uint32_t valU
Definition: sbgTypes.h:140
SBG_INLINE size_t sbgStreamBufferGetSpace(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteStringLE(SbgStreamBuffer *pHandle, const char *pString)
SBG_INLINE size_t sbgStreamBufferReadSizeT64LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt24LE(SbgStreamBuffer *pHandle, int32_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteBuffer(SbgStreamBuffer *pHandle, const void *pBuffer, size_t numBytesToWrite)
SBG_INLINE uint64_t sbgStreamBufferReadUint64LE(SbgStreamBuffer *pHandle)
uint8_t buffer[4]
Definition: sbgTypes.h:103
uint8_t buffer[4]
Definition: sbgTypes.h:112
#define SBG_INLINE
Definition: sbgDefines.h:186
#define SBG_MIN_INT_24
Definition: sbgTypes.h:31
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt32LE(SbgStreamBuffer *pHandle, int32_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteFloatLE(SbgStreamBuffer *pHandle, float value)
SBG_INLINE int32_t sbgStreamBufferReadInt32LE(SbgStreamBuffer *pHandle)
uint64_t value
Definition: sbgTypes.h:129
#define SBG_LOG_ERROR(format,...)
Definition: sbgDebug.h:62
SBG_INLINE uint64_t sbgStreamBufferReadUint48LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32LE(SbgStreamBuffer *pHandle, uint32_t value)
SBG_INLINE int64_t sbgStreamBufferReadInt56LE(SbgStreamBuffer *pHandle)
SBG_INLINE uint32_t sbgStreamBufferReadUint32LE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint16LE(SbgStreamBuffer *pHandle, uint16_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferReadStringLE(SbgStreamBuffer *pHandle, char *pString, size_t maxSize)
SBG_INLINE double sbgStreamBufferReadDoubleLE(SbgStreamBuffer *pHandle)
uint8_t buffer[8]
Definition: sbgTypes.h:130
enum _SbgErrorCode SbgErrorCode
SBG_INLINE int16_t sbgStreamBufferReadInt16LE(SbgStreamBuffer *pHandle)
int32_t value
Definition: sbgTypes.h:102
uint32_t value
Definition: sbgTypes.h:111


sbg_driver
Author(s): SBG Systems
autogenerated on Thu Oct 22 2020 03:47:22