sbgStreamBufferBE.h
Go to the documentation of this file.
1 
21 #ifndef SBG_STREAM_BUFFER_BE_H
22 #define SBG_STREAM_BUFFER_BE_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 == 1)
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[1] = *(pHandle->pCurrentPtr++);
74  bytesValues[0] = *(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 == 1)
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[1] = *(pHandle->pCurrentPtr++);
145  bytesValues[0] = *(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[0] = *(pHandle->pCurrentPtr++); // MSB
209  value.buffer[1] = *(pHandle->pCurrentPtr++);
210  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
211  #else
212  //
213  // Read the each bytes
214  //
215  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
216  value.buffer[2] = *(pHandle->pCurrentPtr++);
217  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
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[0] = *(pHandle->pCurrentPtr++); // MSB
277  value.buffer[1] = *(pHandle->pCurrentPtr++);
278  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
279  #else
280  //
281  // Read the each bytes
282  //
283  value.buffer[3] = *(pHandle->pCurrentPtr++); // MSB
284  value.buffer[2] = *(pHandle->pCurrentPtr++);
285  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
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 == 1)
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[3] = *(pHandle->pCurrentPtr++);
352  bytesValues[2] = *(pHandle->pCurrentPtr++);
353  bytesValues[1] = *(pHandle->pCurrentPtr++);
354  bytesValues[0] = *(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 == 1)
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[3] = *(pHandle->pCurrentPtr++);
425  bytesValues[2] = *(pHandle->pCurrentPtr++);
426  bytesValues[1] = *(pHandle->pCurrentPtr++);
427  bytesValues[0] = *(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[0] = *(pHandle->pCurrentPtr++); // MSB
491  value.buffer[1] = *(pHandle->pCurrentPtr++);
492  value.buffer[2] = *(pHandle->pCurrentPtr++);
493  value.buffer[3] = *(pHandle->pCurrentPtr++);
494  value.buffer[4] = *(pHandle->pCurrentPtr++); // LSB
495  #else
496  //
497  // Read the each bytes
498  //
499  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
500  value.buffer[6] = *(pHandle->pCurrentPtr++);
501  value.buffer[5] = *(pHandle->pCurrentPtr++);
502  value.buffer[4] = *(pHandle->pCurrentPtr++);
503  value.buffer[3] = *(pHandle->pCurrentPtr++); // LSB
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[0] = *(pHandle->pCurrentPtr++); // MSB
563  value.buffer[1] = *(pHandle->pCurrentPtr++);
564  value.buffer[2] = *(pHandle->pCurrentPtr++);
565  value.buffer[3] = *(pHandle->pCurrentPtr++);
566  value.buffer[4] = *(pHandle->pCurrentPtr++); // LSB
567  #else
568  //
569  // Read the each bytes
570  //
571  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
572  value.buffer[6] = *(pHandle->pCurrentPtr++);
573  value.buffer[5] = *(pHandle->pCurrentPtr++);
574  value.buffer[4] = *(pHandle->pCurrentPtr++);
575  value.buffer[3] = *(pHandle->pCurrentPtr++); // LSB
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[0] = *(pHandle->pCurrentPtr++); // MSB
635  value.buffer[1] = *(pHandle->pCurrentPtr++);
636  value.buffer[2] = *(pHandle->pCurrentPtr++);
637  value.buffer[3] = *(pHandle->pCurrentPtr++);
638  value.buffer[4] = *(pHandle->pCurrentPtr++);
639  value.buffer[5] = *(pHandle->pCurrentPtr++); // LSB
640  #else
641  //
642  // Read the each bytes
643  //
644  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
645  value.buffer[6] = *(pHandle->pCurrentPtr++);
646  value.buffer[5] = *(pHandle->pCurrentPtr++);
647  value.buffer[4] = *(pHandle->pCurrentPtr++);
648  value.buffer[3] = *(pHandle->pCurrentPtr++);
649  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
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[0] = *(pHandle->pCurrentPtr++); // MSB
709  value.buffer[1] = *(pHandle->pCurrentPtr++);
710  value.buffer[2] = *(pHandle->pCurrentPtr++);
711  value.buffer[3] = *(pHandle->pCurrentPtr++);
712  value.buffer[4] = *(pHandle->pCurrentPtr++);
713  value.buffer[5] = *(pHandle->pCurrentPtr++); // LSB
714  #else
715  //
716  // Read the each bytes
717  //
718  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
719  value.buffer[6] = *(pHandle->pCurrentPtr++);
720  value.buffer[5] = *(pHandle->pCurrentPtr++);
721  value.buffer[4] = *(pHandle->pCurrentPtr++);
722  value.buffer[3] = *(pHandle->pCurrentPtr++);
723  value.buffer[2] = *(pHandle->pCurrentPtr++); // LSB
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[0] = *(pHandle->pCurrentPtr++); // MSB
783  value.buffer[1] = *(pHandle->pCurrentPtr++);
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++); // LSB
789  #else
790  //
791  // Read the each bytes
792  //
793  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
794  value.buffer[6] = *(pHandle->pCurrentPtr++);
795  value.buffer[5] = *(pHandle->pCurrentPtr++);
796  value.buffer[4] = *(pHandle->pCurrentPtr++);
797  value.buffer[3] = *(pHandle->pCurrentPtr++);
798  value.buffer[2] = *(pHandle->pCurrentPtr++);
799  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
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[0] = *(pHandle->pCurrentPtr++); // MSB
859  value.buffer[1] = *(pHandle->pCurrentPtr++);
860  value.buffer[2] = *(pHandle->pCurrentPtr++);
861  value.buffer[3] = *(pHandle->pCurrentPtr++);
862  value.buffer[4] = *(pHandle->pCurrentPtr++);
863  value.buffer[5] = *(pHandle->pCurrentPtr++);
864  value.buffer[6] = *(pHandle->pCurrentPtr++); // LSB
865  #else
866  //
867  // Read the each bytes
868  //
869  value.buffer[7] = *(pHandle->pCurrentPtr++); // MSB
870  value.buffer[6] = *(pHandle->pCurrentPtr++);
871  value.buffer[5] = *(pHandle->pCurrentPtr++);
872  value.buffer[4] = *(pHandle->pCurrentPtr++);
873  value.buffer[3] = *(pHandle->pCurrentPtr++);
874  value.buffer[2] = *(pHandle->pCurrentPtr++);
875  value.buffer[1] = *(pHandle->pCurrentPtr++); // LSB
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 == 1)
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  highPart = sbgStreamBufferReadUint32BE(pHandle);
943  lowPart = sbgStreamBufferReadUint32BE(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 == 1)
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  highPart = sbgStreamBufferReadUint32BE(pHandle);
1015  lowPart = sbgStreamBufferReadUint32BE(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 0ll;
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)sbgStreamBufferReadUint32BE(pHandle);
1054 }
1055 
1062 {
1063  uint64_t size;
1064 
1065  //
1066  // Just call the read method for uint64_t
1067  //
1068  size = sbgStreamBufferReadUint64BE(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 = sbgStreamBufferReadUint32BE(pHandle);
1109 
1110  //
1111  // Return the float using an union to avoid compiller 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 = sbgStreamBufferReadUint64BE(pHandle);
1158 
1159  //
1160  // Return the double using an union to avoid compiller 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 == 1)
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);
1225  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1226  #else
1227  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1228  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
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 == 1)
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);
1286  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1287  #else
1288  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1289  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
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 
1312 {
1313  //
1314  // Check input parameters
1315  //
1316  assert(pHandle);
1317 
1318  //
1319  // Test if we haven't already an error
1320  //
1321  if (pHandle->errorCode == SBG_NO_ERROR)
1322  {
1323  //
1324  // Make sure that the value is within 24 bit bonds
1325  //
1326  if ( (value >= SBG_MIN_INT_24) && (value <= SBG_MAX_INT_24) )
1327  {
1328  //
1329  // Test if we can access this item
1330  //
1331  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(int8_t))
1332  {
1333  //
1334  // Store data according to platform endianness
1335  //
1336  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1337  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1338  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1339  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1340  #else
1341  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1342  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1343  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1344  #endif
1345  }
1346  else
1347  {
1348  //
1349  // We are accessing a data that is outside the stream buffer
1350  //
1351  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1352  }
1353  }
1354  else
1355  {
1356  //
1357  // The input value is not within a 24 bit integer bounds
1358  //
1359  pHandle->errorCode = SBG_INVALID_PARAMETER;
1360  }
1361  }
1362 
1363  return pHandle->errorCode;
1364 }
1365 
1373 {
1374  //
1375  // Check input parameters
1376  //
1377  assert(pHandle);
1378 
1379  //
1380  // Test if we haven't already an error
1381  //
1382  if (pHandle->errorCode == SBG_NO_ERROR)
1383  {
1384  //
1385  // Make sure that the value is within 24 bit bonds
1386  //
1387  if (value <= SBG_MAX_UINT_24)
1388  {
1389  //
1390  // Test if we can access this item
1391  //
1392  if (sbgStreamBufferGetSpace(pHandle) >= 3*sizeof(uint8_t))
1393  {
1394  //
1395  // Store data according to platform endianness
1396  //
1397  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1398  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1399  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1400  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1401  #else
1402  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1403  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1404  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1405  #endif
1406  }
1407  else
1408  {
1409  //
1410  // We are accessing a data that is outside the stream buffer
1411  //
1412  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1413  }
1414  }
1415  else
1416  {
1417  //
1418  // The input value is not within a 24 bit integer bounds
1419  //
1420  pHandle->errorCode = SBG_INVALID_PARAMETER;
1421  }
1422  }
1423 
1424  return pHandle->errorCode;
1425 }
1426 
1434 {
1435  //
1436  // Check input parameters
1437  //
1438  assert(pHandle);
1439 
1440  //
1441  // Test if we haven't already an error
1442  //
1443  if (pHandle->errorCode == SBG_NO_ERROR)
1444  {
1445  //
1446  // Test if we can access this item
1447  //
1448  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int32_t))
1449  {
1450  //
1451  // Test if the platform supports un-aligned access and if the endianness is the same
1452  //
1453  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 1)
1454  //
1455  // Write the value
1456  //
1457  *((int32_t*)(pHandle->pCurrentPtr)) = value;
1458 
1459  //
1460  // Increment the current pointer
1461  //
1462  pHandle->pCurrentPtr += sizeof(int32_t);
1463  #else
1464  //
1465  // Store data according to platform endianness
1466  //
1467  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1468  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1469  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1470  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1471  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1472  #else
1473  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1474  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1475  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1476  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1477  #endif
1478  #endif
1479  }
1480  else
1481  {
1482  //
1483  // We are accessing a data that is outside the stream buffer
1484  //
1485  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1486  }
1487  }
1488 
1489  return pHandle->errorCode;
1490 }
1491 
1499 {
1500  //
1501  // Check input parameters
1502  //
1503  assert(pHandle);
1504 
1505  //
1506  // Test if we haven't already an error
1507  //
1508  if (pHandle->errorCode == SBG_NO_ERROR)
1509  {
1510  //
1511  // Test if we can access this item
1512  //
1513  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint32_t))
1514  {
1515  //
1516  // Test if the platform supports un-aligned access and if the endianness is the same
1517  //
1518  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 1)
1519  //
1520  // Write the value
1521  //
1522  *((uint32_t*)(pHandle->pCurrentPtr)) = value;
1523 
1524  //
1525  // Increment the current pointer
1526  //
1527  pHandle->pCurrentPtr += sizeof(uint32_t);
1528  #else
1529  //
1530  // Store data according to platform endianness
1531  //
1532  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1533  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1534  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1535  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1536  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1537  #else
1538  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1539  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1540  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1541  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1542  #endif
1543  #endif
1544  }
1545  else
1546  {
1547  //
1548  // We are accessing a data that is outside the stream buffer
1549  //
1550  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1551  }
1552  }
1553 
1554  return pHandle->errorCode;
1555 }
1556 
1564 {
1565  //
1566  // Check input parameters
1567  //
1568  assert(pHandle);
1569 
1570  //
1571  // Test if we haven't already an error
1572  //
1573  if (pHandle->errorCode == SBG_NO_ERROR)
1574  {
1575  //
1576  // Test if we can access this item
1577  //
1578  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(int64_t))
1579  {
1580  //
1581  // Test if the platform supports un-aligned access and if the endianness is the same
1582  //
1583  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 1)
1584  //
1585  // Write the value
1586  //
1587  *((int64_t*)(pHandle->pCurrentPtr)) = value;
1588 
1589  //
1590  // Increment the current pointer
1591  //
1592  pHandle->pCurrentPtr += sizeof(int64_t);
1593  #else
1594  //
1595  // Store data according to platform endianness
1596  //
1597  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1598  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1599  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1600  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1601  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1602  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1603  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1604  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1605  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1606  #else
1607  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1608  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1609  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1610  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1611  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1612  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1613  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1614  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1615  #endif
1616  #endif
1617  }
1618  else
1619  {
1620  //
1621  // We are accessing a data that is outside the stream buffer
1622  //
1623  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1624  }
1625  }
1626 
1627  return pHandle->errorCode;
1628 }
1629 
1637 {
1638  //
1639  // Check input parameters
1640  //
1641  assert(pHandle);
1642 
1643  //
1644  // Test if we haven't already an error
1645  //
1646  if (pHandle->errorCode == SBG_NO_ERROR)
1647  {
1648  //
1649  // Test if we can access this item
1650  //
1651  if (sbgStreamBufferGetSpace(pHandle) >= sizeof(uint64_t))
1652  {
1653  //
1654  // Test if the platform supports un-aligned access and if the endianness is the same
1655  //
1656  #if (SBG_CONFIG_UNALIGNED_ACCESS_AUTH == 1) && (SBG_CONFIG_BIG_ENDIAN == 1)
1657  //
1658  // Write the value
1659  //
1660  *((uint64_t*)(pHandle->pCurrentPtr)) = value;
1661 
1662  //
1663  // Increment the current pointer
1664  //
1665  pHandle->pCurrentPtr += sizeof(uint64_t);
1666  #else
1667  //
1668  // Store data according to platform endianness
1669  //
1670  #if (SBG_CONFIG_BIG_ENDIAN == 1)
1671  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1672  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1673  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1674  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1675  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1676  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1677  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1678  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1679  #else
1680  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 56);
1681  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 48);
1682  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 40);
1683  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 32);
1684  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 24);
1685  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 16);
1686  *(pHandle->pCurrentPtr++) = (uint8_t)(value >> 8);
1687  *(pHandle->pCurrentPtr++) = (uint8_t)(value);
1688  #endif
1689  #endif
1690  }
1691  else
1692  {
1693  //
1694  // We are accessing a data that is outside the stream buffer
1695  //
1696  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1697  }
1698  }
1699 
1700  return pHandle->errorCode;
1701 }
1702 
1710 {
1711  //
1712  // Check input parameters
1713  //
1714  assert(pHandle);
1715 
1716  //
1717  // Make sure the provided size_t value doesn't exceed a uint32_t storage
1718  //
1719  assert(value <= UINT32_MAX);
1720 
1721  //
1722  // Call the write method to store a uint32_t
1723  //
1724  return sbgStreamBufferWriteUint32BE(pHandle, (uint32_t)value);
1725 }
1726 
1734 {
1735  //
1736  // Check input parameters
1737  //
1738  assert(pHandle);
1739 
1740  //
1741  // Call the write method to store a uint64_t
1742  //
1743  return sbgStreamBufferWriteUint64BE(pHandle, (uint64_t)value);
1744 }
1745 
1753 {
1754  FloatNint floatInt;
1755 
1756  //
1757  // Check input parameters
1758  //
1759  assert(pHandle);
1760 
1761  //
1762  // Test if we haven't already an error
1763  //
1764  if (pHandle->errorCode == SBG_NO_ERROR)
1765  {
1766  //
1767  // We use an union to avoid compiler cast
1768  //
1769  floatInt.valF = value;
1770 
1771  //
1772  // Write this float as an uint32_t
1773  //
1774  return sbgStreamBufferWriteUint32BE(pHandle, floatInt.valU);
1775  }
1776 
1777  return pHandle->errorCode;
1778 }
1779 
1787 {
1788  DoubleNint doubleInt;
1789 
1790  //
1791  // Check input parameters
1792  //
1793  assert(pHandle);
1794 
1795  //
1796  // Test if we haven't already an error
1797  //
1798  if (pHandle->errorCode == SBG_NO_ERROR)
1799  {
1800  //
1801  // We use an union to avoid compiler cast
1802  //
1803  doubleInt.valF = value;
1804 
1805  //
1806  // Write this float as an uint64_t
1807  //
1808  return sbgStreamBufferWriteUint64BE(pHandle, doubleInt.valU);
1809  }
1810 
1811  return pHandle->errorCode;
1812 }
1813 
1823 SBG_INLINE SbgErrorCode sbgStreamBufferReadStringBE(SbgStreamBuffer *pHandle, char *pString, size_t maxSize)
1824 {
1825  size_t stringLength;
1826 
1827  //
1828  // Check input parameters
1829  //
1830  assert(pHandle);
1831  assert(pString);
1832  assert(maxSize > 0);
1833 
1834  //
1835  // Test if we haven't already an error
1836  //
1837  if (pHandle->errorCode == SBG_NO_ERROR)
1838  {
1839  //
1840  // The C string are stored in a stream buffer with a 32 bit size length and then the buffer itself
1841  //
1842  stringLength = sbgStreamBufferReadSizeT32BE(pHandle);
1843 
1844  if (stringLength <= maxSize)
1845  {
1846  //
1847  // Read the string buffer itself
1848  //
1849  sbgStreamBufferReadBuffer(pHandle, pString, stringLength);
1850  }
1851  else
1852  {
1853  pHandle->errorCode = SBG_BUFFER_OVERFLOW;
1854  SBG_LOG_ERROR(pHandle->errorCode, "Trying to store a string of %u bytes into a buffer of %u bytes.", stringLength, maxSize);
1855  }
1856  }
1857 
1858  return pHandle->errorCode;
1859 }
1860 
1868 {
1869  size_t stringLength;
1870 
1871  //
1872  // Check input parameters
1873  //
1874  assert(pHandle);
1875  assert(pString);
1876 
1877  //
1878  // Test if we haven't already an error
1879  //
1880  if (pHandle->errorCode == SBG_NO_ERROR)
1881  {
1882  //
1883  // We write C string using a 32 bit size_t as the string length including the NULL char
1884  // We should thus make sure the provided string isn't too big to fit in a 32 bits size_t
1885  //
1886  stringLength = strlen(pString)+1;
1887 
1888  if (stringLength <= UINT32_MAX)
1889  {
1890  //
1891  // Write the string length
1892  //
1893  if (sbgStreamBufferWriteSizeT32BE(pHandle, stringLength) == SBG_NO_ERROR)
1894  {
1895  //
1896  // Write the string buffer itself
1897  //
1898  sbgStreamBufferWriteBuffer(pHandle, pString, stringLength);
1899  }
1900  }
1901  else
1902  {
1903  pHandle->errorCode = SBG_INVALID_PARAMETER;
1904  SBG_LOG_ERROR(pHandle->errorCode, "The provided string is too big to fit in a 32 bit size_t");
1905  }
1906  }
1907 
1908  return pHandle->errorCode;
1909 }
1910 
1911 #endif /* SBG_STREAM_BUFFER_BE_H */
uint8_t buffer[8]
Definition: sbgTypes.h:121
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint24BE(SbgStreamBuffer *pHandle, uint32_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteFloatBE(SbgStreamBuffer *pHandle, float value)
double valF
Definition: sbgTypes.h:148
SBG_INLINE int32_t sbgStreamBufferReadInt24BE(SbgStreamBuffer *pHandle)
SBG_INLINE float sbgStreamBufferReadFloatBE(SbgStreamBuffer *pHandle)
#define SBG_MAX_UINT_24
Definition: sbgTypes.h:33
SBG_INLINE SbgErrorCode sbgStreamBufferReadStringBE(SbgStreamBuffer *pHandle, char *pString, size_t maxSize)
SBG_INLINE uint64_t sbgStreamBufferReadUint64BE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt64BE(SbgStreamBuffer *pHandle, int64_t value)
Used to read/write data from/to a memory buffer stream.
SBG_INLINE SbgErrorCode sbgStreamBufferWriteSizeT64BE(SbgStreamBuffer *pHandle, size_t value)
SBG_INLINE uint32_t sbgStreamBufferReadUint32BE(SbgStreamBuffer *pHandle)
SBG_INLINE int64_t sbgStreamBufferReadInt56BE(SbgStreamBuffer *pHandle)
int64_t value
Definition: sbgTypes.h:120
SBG_INLINE int64_t sbgStreamBufferReadUint56BE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint64BE(SbgStreamBuffer *pHandle, uint64_t value)
SBG_INLINE int64_t sbgStreamBufferReadInt48BE(SbgStreamBuffer *pHandle)
SBG_INLINE size_t sbgStreamBufferReadSizeT32BE(SbgStreamBuffer *pHandle)
SBG_INLINE double sbgStreamBufferReadDoubleBE(SbgStreamBuffer *pHandle)
uint64_t valU
Definition: sbgTypes.h:149
SBG_INLINE SbgErrorCode sbgStreamBufferWriteDoubleBE(SbgStreamBuffer *pHandle, double value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt32BE(SbgStreamBuffer *pHandle, int32_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteSizeT32BE(SbgStreamBuffer *pHandle, size_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint16BE(SbgStreamBuffer *pHandle, uint16_t value)
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 sbgStreamBufferWriteInt24BE(SbgStreamBuffer *pHandle, int32_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteBuffer(SbgStreamBuffer *pHandle, const void *pBuffer, size_t numBytesToWrite)
SBG_INLINE uint64_t sbgStreamBufferReadUint48BE(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
SBG_INLINE SbgErrorCode sbgStreamBufferWriteInt16BE(SbgStreamBuffer *pHandle, int16_t value)
#define SBG_MIN_INT_24
Definition: sbgTypes.h:31
SBG_INLINE int64_t sbgStreamBufferReadInt40BE(SbgStreamBuffer *pHandle)
SBG_INLINE int64_t sbgStreamBufferReadInt64BE(SbgStreamBuffer *pHandle)
uint64_t value
Definition: sbgTypes.h:129
#define SBG_LOG_ERROR(format,...)
Definition: sbgDebug.h:62
SBG_INLINE uint64_t sbgStreamBufferReadUint40BE(SbgStreamBuffer *pHandle)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteUint32BE(SbgStreamBuffer *pHandle, uint32_t value)
SBG_INLINE SbgErrorCode sbgStreamBufferWriteStringBE(SbgStreamBuffer *pHandle, const char *pString)
SBG_INLINE int32_t sbgStreamBufferReadInt32BE(SbgStreamBuffer *pHandle)
SBG_INLINE int16_t sbgStreamBufferReadInt16BE(SbgStreamBuffer *pHandle)
SBG_INLINE size_t sbgStreamBufferReadSizeT64BE(SbgStreamBuffer *pHandle)
SBG_INLINE uint32_t sbgStreamBufferReadUint24BE(SbgStreamBuffer *pHandle)
SBG_INLINE uint16_t sbgStreamBufferReadUint16BE(SbgStreamBuffer *pHandle)
uint8_t buffer[8]
Definition: sbgTypes.h:130
enum _SbgErrorCode SbgErrorCode
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