File: binaryreader.h

package info (click to toggle)
martchus-cpp-utilities 5.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: cpp: 12,679; awk: 18; ansic: 12; makefile: 10
file content (738 lines) | stat: -rw-r--r-- 22,477 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
#ifndef IOUTILITIES_BINERYREADER_H
#define IOUTILITIES_BINERYREADER_H

#include "../conversion/binaryconversion.h"

#include <istream>
#include <string>
#include <vector>

namespace CppUtilities {
class CPP_UTILITIES_EXPORT BinaryReader {

public:
    BinaryReader(std::istream *stream, bool giveOwnership = false);
    BinaryReader(const BinaryReader &other);
    BinaryReader &operator=(const BinaryReader &rhs) = delete;
    ~BinaryReader();

    const std::istream *stream() const;
    std::istream *stream();
    void setStream(std::istream *stream, bool giveOwnership = false);
    bool hasOwnership() const;
    void giveOwnership();
    void detatchOwnership();
    bool fail() const;
    bool eof() const;
    bool canRead() const;
    std::istream::pos_type readStreamsize();
    std::istream::pos_type readRemainingBytes();
    void read(char *buffer, std::streamsize length);
    void read(std::uint8_t *buffer, std::streamsize length);
    void read(std::vector<char> &buffer, std::streamsize length);
    std::int16_t readInt16BE();
    std::uint16_t readUInt16BE();
    std::int32_t readInt24BE();
    std::uint32_t readUInt24BE();
    std::int32_t readInt32BE();
    std::uint32_t readUInt32BE();
    std::int64_t readInt40BE();
    std::uint64_t readUInt40BE();
    std::int64_t readInt56BE();
    std::uint64_t readUInt56BE();
    std::int64_t readInt64BE();
    std::uint64_t readUInt64BE();
    std::uint64_t readVariableLengthUIntBE();
    float readFloat32BE();
    double readFloat64BE();
    std::int16_t readInt16LE();
    std::uint16_t readUInt16LE();
    std::int32_t readInt24LE();
    std::uint32_t readUInt24LE();
    std::int32_t readInt32LE();
    std::uint32_t readUInt32LE();
    std::int64_t readInt40LE();
    std::uint64_t readUInt40LE();
    std::int64_t readInt56LE();
    std::uint64_t readUInt56LE();
    std::int64_t readInt64LE();
    std::uint64_t readUInt64LE();
    std::uint64_t readVariableLengthUIntLE();
    float readFloat32LE();
    double readFloat64LE();
    char readChar();
    std::uint8_t readByte();
    bool readBool();
    std::string readLengthPrefixedString();
    std::string readString(std::size_t length);
    std::string readTerminatedString(std::uint8_t termination = 0);
    std::string readTerminatedString(std::size_t maxBytesToRead, std::uint8_t termination = 0);
    std::uint32_t readSynchsafeUInt32BE();
    float readFixed8BE();
    float readFixed16BE();
    std::uint32_t readSynchsafeUInt32LE();
    float readFixed8LE();
    float readFixed16LE();
    std::uint32_t readCrc32(std::size_t length);
    static std::uint32_t computeCrc32(const char *buffer, std::size_t length);
    static const std::uint32_t crc32Table[];

    // declare further overloads for read() to ease use of BinaryReader in templates
    void read(char &oneCharacter);
    void read(std::uint8_t &oneByte);
    void read(bool &oneBool);
    void read(std::string &lengthPrefixedString);
    void read(std::int16_t &one16BitInt);
    void read(std::uint16_t &one16BitUInt);
    void read(std::int32_t &one32BitInt);
    void read(std::uint32_t &one32BitUInt);
    void read(std::int64_t &one64BitInt);
    void read(std::uint64_t &one64BitUInt);
    void read(float &one32BitFloat);
    void read(double &one64BitFloat);

private:
    void bufferVariableLengthInteger();

    std::istream *m_stream;
    bool m_ownership;
    char m_buffer[8];
};

/*!
 * \brief Constructs a new BinaryReader.
 * \param stream Specifies the stream to read from.
 * \param giveOwnership Specifies whether the reader should take ownership.
 */
inline BinaryReader::BinaryReader(std::istream *stream, bool giveOwnership)
    : m_stream(stream)
    , m_ownership(giveOwnership)
{
}

/*!
 * \brief Copies the specified BinaryReader.
 * \remarks The copy will not take ownership over the stream.
 */
inline BinaryReader::BinaryReader(const BinaryReader &other)
    : m_stream(other.m_stream)
    , m_ownership(false)
{
}

/*!
 * \brief Destroys the BinaryReader.
 */
inline BinaryReader::~BinaryReader()
{
    if (m_ownership) {
        delete m_stream;
    }
}

/*!
 * \brief Returns a pointer to the stream the reader will read from when calling one of the read-methods.
 *
 * \sa setStream()
 */
inline std::istream *BinaryReader::stream()
{
    return m_stream;
}

/*!
 * \brief Returns a pointer to the stream the reader will read from when calling one of the read-methods.
 *
 * \sa setStream()
 */
inline const std::istream *BinaryReader::stream() const
{
    return m_stream;
}

/*!
 * \brief Returns whether the reader takes ownership over the assigned stream.
 *
 * \sa setStream()
 * \sa giveOwnership()
 * \sa detatchOwnership()
 */
inline bool BinaryReader::hasOwnership() const
{
    return m_ownership;
}

/*!
 * \brief The reader will take ownership over the assigned stream.
 *
 * \sa setStream()
 * \sa detatchOwnership()
 * \sa hasOwnership()
 */
inline void BinaryReader::giveOwnership()
{
    if (m_stream) {
        m_ownership = true;
    }
}

/*!
 * \brief The reader will not take ownership over the assigned stream.
 *
 * \sa setStream()
 * \sa giveOwnership()
 * \sa hasOwnership()
 */
inline void BinaryReader::detatchOwnership()
{
    m_ownership = false;
}

/*!
 * \brief Returns an indication whether the fail bit of the assigned stream is set.
 */
inline bool BinaryReader::fail() const
{
    return m_stream ? m_stream->fail() : false;
}

/*!
 * \brief Returns an indication whether the end-of-stream bit of the assigned stream is set.
 */
inline bool BinaryReader::eof() const
{
    return m_stream && m_stream->eof();
}

/*!
 * \brief Returns an indication whether a stream is assigned the reader can read from.
 */
inline bool BinaryReader::canRead() const
{
    return m_stream && m_stream->good();
}

/*!
 * \brief Reads the specified number of characters from the stream in the character array.
 */
inline void BinaryReader::read(char *buffer, std::streamsize length)
{
    m_stream->read(buffer, length);
}

/*!
 * \brief Reads the specified number of bytes from the stream in the character array.
 */
inline void BinaryReader::read(std::uint8_t *buffer, std::streamsize length)
{
    m_stream->read(reinterpret_cast<char *>(buffer), length);
}

/*!
 * \brief Reads the specified number of bytes from the stream in the specified \a buffer.
 */
inline void BinaryReader::read(std::vector<char> &buffer, std::streamsize length)
{
    buffer.resize(static_cast<std::vector<char>::size_type>(length));
    m_stream->read(buffer.data(), length);
}

/*!
 * \brief Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
 */
inline std::int16_t BinaryReader::readInt16BE()
{
    m_stream->read(m_buffer, sizeof(std::int16_t));
    return BE::toInt<std::int16_t>(m_buffer);
}

/*!
 * \brief Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
 */
inline std::uint16_t BinaryReader::readUInt16BE()
{
    m_stream->read(m_buffer, sizeof(std::uint16_t));
    return BE::toInt<std::uint16_t>(m_buffer);
}

/*!
 * \brief Reads a 24-bit big endian signed integer from the current stream and advances the current position of the stream by three bytes.
 */
inline std::int32_t BinaryReader::readInt24BE()
{
    *m_buffer = 0;
    m_stream->read(m_buffer + 1, 3);
    auto val = BE::toInt<std::int32_t>(m_buffer);
    if (val >= 0x800000) {
        val = -(0x1000000 - val);
    }
    return val;
}

/*!
 * \brief Reads a 24-bit big endian unsigned integer from the current stream and advances the current position of the stream by three bytes.
 */
inline std::uint32_t BinaryReader::readUInt24BE()
{
    *m_buffer = 0;
    m_stream->read(m_buffer + 1, 3);
    return BE::toInt<std::uint32_t>(m_buffer);
}

/*!
 * \brief Reads a 32-bit big endian signed integer from the current stream and advances the current position of the stream by four bytes.
 */
inline std::int32_t BinaryReader::readInt32BE()
{
    m_stream->read(m_buffer, sizeof(std::int32_t));
    return BE::toInt<std::int32_t>(m_buffer);
}

/*!
 * \brief Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
 */
inline std::uint32_t BinaryReader::readUInt32BE()
{
    m_stream->read(m_buffer, sizeof(std::uint32_t));
    return BE::toInt<std::uint32_t>(m_buffer);
}

/*!
 * \brief Reads a 40-bit big endian signed integer from the current stream and advances the current position of the stream by five bytes.
 */
inline std::int64_t BinaryReader::readInt40BE()
{
    *m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
    m_stream->read(m_buffer + 3, 5);
    auto val = BE::toInt<std::int64_t>(m_buffer);
    if (val >= 0x8000000000) {
        val = -(0x10000000000 - val);
    }
    return val;
}

/*!
 * \brief Reads a 40-bit big endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
 */
inline std::uint64_t BinaryReader::readUInt40BE()
{
    *m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
    m_stream->read(m_buffer + 3, 5);
    return BE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads a 56-bit big endian signed integer from the current stream and advances the current position of the stream by seven bytes.
 */
inline std::int64_t BinaryReader::readInt56BE()
{
    *m_buffer = 0;
    m_stream->read(m_buffer + 1, 7);
    auto val = BE::toInt<std::int64_t>(m_buffer);
    if (val >= 0x80000000000000) {
        val = -(0x100000000000000 - val);
    }
    return val;
}

/*!
 * \brief Reads a 56-bit big endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
 */
inline std::uint64_t BinaryReader::readUInt56BE()
{
    *m_buffer = 0;
    m_stream->read(m_buffer + 1, 7);
    return BE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes.
 */
inline std::int64_t BinaryReader::readInt64BE()
{
    m_stream->read(m_buffer, sizeof(std::int64_t));
    return BE::toInt<std::int64_t>(m_buffer);
}

/*!
 * \brief Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
 */
inline std::uint64_t BinaryReader::readUInt64BE()
{
    m_stream->read(m_buffer, sizeof(std::uint64_t));
    return BE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads an up to 8 byte long big endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte.
 * \throws Throws ConversionException if the size of the integer exceeds the maximum.
 */
inline std::uint64_t BinaryReader::readVariableLengthUIntBE()
{
    bufferVariableLengthInteger();
    return BE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes.
 */
inline float BinaryReader::readFloat32BE()
{
    m_stream->read(m_buffer, sizeof(float));
    return BE::toFloat32(m_buffer);
}

/*!
 * \brief Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes.
 */
inline double BinaryReader::readFloat64BE()
{
    m_stream->read(m_buffer, sizeof(double));
    return BE::toFloat64(m_buffer);
}

/*!
 * \brief Reads a 16-bit little endian signed integer from the current stream and advances the current position of the stream by two bytes.
 */
inline std::int16_t BinaryReader::readInt16LE()
{
    m_stream->read(m_buffer, sizeof(std::int16_t));
    return LE::toInt<std::int16_t>(m_buffer);
}

/*!
 * \brief Reads a 16-bit little endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
 */
inline std::uint16_t BinaryReader::readUInt16LE()
{
    m_stream->read(m_buffer, sizeof(std::uint16_t));
    return LE::toInt<std::uint16_t>(m_buffer);
}

/*!
 * \brief Reads a 24-bit little endian signed integer from the current stream and advances the current position of the stream by three bytes.
 */
inline std::int32_t BinaryReader::readInt24LE()
{
    *(m_buffer + 3) = 0;
    m_stream->read(m_buffer, 3);
    auto val = LE::toInt<std::int32_t>(m_buffer);
    if (val >= 0x800000) {
        val = -(0x1000000 - val);
    }
    return val;
}

/*!
 * \brief Reads a 24-bit little endian unsigned integer from the current stream and advances the current position of the stream by three bytes.
 */
inline std::uint32_t BinaryReader::readUInt24LE()
{
    *(m_buffer + 3) = 0;
    m_stream->read(m_buffer, 3);
    return LE::toInt<std::uint32_t>(m_buffer);
}

/*!
 * \brief Reads a 32-bit little endian signed integer from the current stream and advances the current position of the stream by four bytes.
 */
inline std::int32_t BinaryReader::readInt32LE()
{
    m_stream->read(m_buffer, sizeof(std::int32_t));
    return LE::toInt<std::int32_t>(m_buffer);
}

/*!
 * \brief Reads a 32-bit little endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
 */
inline std::uint32_t BinaryReader::readUInt32LE()
{
    m_stream->read(m_buffer, sizeof(std::uint32_t));
    return LE::toInt<std::uint32_t>(m_buffer);
}

/*!
 * \brief Reads a 40-bit little endian signed integer from the current stream and advances the current position of the stream by five bytes.
 */
inline std::int64_t BinaryReader::readInt40LE()
{
    *(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
    m_stream->read(m_buffer, 5);
    auto val = LE::toInt<std::int64_t>(m_buffer);
    if (val >= 0x8000000000) {
        val = -(0x10000000000 - val);
    }
    return val;
}

/*!
 * \brief Reads a 40-bit little endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
 */
inline std::uint64_t BinaryReader::readUInt40LE()
{
    *(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
    m_stream->read(m_buffer, 5);
    return LE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads a 56-bit little endian signed integer from the current stream and advances the current position of the stream by seven bytes.
 */
inline std::int64_t BinaryReader::readInt56LE()
{
    *(m_buffer + 7) = 0;
    m_stream->read(m_buffer, 7);
    auto val = LE::toInt<std::int64_t>(m_buffer);
    if (val >= 0x80000000000000) {
        val = -(0x100000000000000 - val);
    }
    return val;
}

/*!
 * \brief Reads a 56-bit little endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
 */
inline std::uint64_t BinaryReader::readUInt56LE()
{
    *(m_buffer + 7) = 0;
    m_stream->read(m_buffer, 7);
    return LE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads a 64-bit little endian signed integer from the current stream and advances the current position of the stream by eight bytes.
 */
inline std::int64_t BinaryReader::readInt64LE()
{
    m_stream->read(m_buffer, sizeof(std::int64_t));
    return LE::toInt<std::int64_t>(m_buffer);
}

/*!
 * \brief Reads a 64-bit little endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
 */
inline std::uint64_t BinaryReader::readUInt64LE()
{
    m_stream->read(m_buffer, sizeof(std::uint64_t));
    return LE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads an up to 8 byte long little endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte.
 * \throws Throws ConversionException if the size of the integer exceeds the maximum.
 */
inline std::uint64_t BinaryReader::readVariableLengthUIntLE()
{
    bufferVariableLengthInteger();
    return LE::toInt<std::uint64_t>(m_buffer);
}

/*!
 * \brief Reads a 32-bit little endian floating point value from the current stream and advances the current position of the stream by four bytes.
 */
inline float BinaryReader::readFloat32LE()
{
    m_stream->read(m_buffer, sizeof(float));
    return LE::toFloat32(m_buffer);
}

/*!
 * \brief Reads a 64-bit little endian floating point value from the current stream and advances the current position of the stream by eight bytes.
 */
inline double BinaryReader::readFloat64LE()
{
    m_stream->read(m_buffer, sizeof(double));
    return LE::toFloat64(m_buffer);
}

/*!
 * \brief Reads a single character from the current stream and advances the current position of the stream by one byte.
 */
inline char BinaryReader::readChar()
{
    m_stream->read(m_buffer, sizeof(char));
    return m_buffer[0];
}

/*!
 * \brief Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte.
 */
inline uint8_t BinaryReader::readByte()
{
    m_stream->read(m_buffer, sizeof(char));
    return static_cast<std::uint8_t>(m_buffer[0]);
}

/*!
 * \brief Reads a boolean value from the current stream and advances the current position of the stream by one byte.
 * \sa BitReader
 */
inline bool BinaryReader::readBool()
{
    return readByte() != 0;
}

/*!
 * \brief Reads a length prefixed string from the current stream.
 * \remarks Reads the length prefix from the stream and then a string of the denoted length.
 *          Advances the current position of the stream by the denoted length of the string plus the prefix length.
 */
inline std::string BinaryReader::readLengthPrefixedString()
{
    return readString(readVariableLengthUIntBE());
}

/*!
 * \brief Reads a 32-bit big endian synchsafe integer from the current stream and advances the current position of the stream by four bytes.
 * \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
 * \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
 */
inline std::uint32_t BinaryReader::readSynchsafeUInt32BE()
{
    return toNormalInt(readUInt32BE());
}

/*!
 * \brief Reads a 8.8 fixed point big endian representation from the current stream and returns it as 32-bit floating point value.
 */
inline float BinaryReader::readFixed8BE()
{
    return toFloat32(readUInt16BE());
}

/*!
 * \brief Reads a 16.16 fixed point big endian representation from the current stream and returns it as 32-bit floating point value.
 */
inline float BinaryReader::readFixed16BE()
{
    return toFloat32(readUInt32BE());
}

/*!
 * \brief Reads a 32-bit little endian synchsafe integer from the current stream and advances the current position of the stream by four bytes.
 * \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
 * \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
 */
inline std::uint32_t BinaryReader::readSynchsafeUInt32LE()
{
    return toNormalInt(readUInt32LE());
}

/*!
 * \brief Reads a 8.8 fixed point little endian representation from the current stream and returns it as 32-bit floating point value.
 */
inline float BinaryReader::readFixed8LE()
{
    return toFloat32(readUInt16LE());
}

/*!
 * \brief Reads a 16.16 fixed point little endian representation from the current stream and returns it as 32-bit floating point value.
 */
inline float BinaryReader::readFixed16LE()
{
    return toFloat32(readUInt32LE());
}

/*!
 * \brief Reads a single character from the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryReader::read(char &oneCharacter)
{
    oneCharacter = readChar();
}

/*!
 * \brief Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryReader::read(std::uint8_t &oneByte)
{
    oneByte = readByte();
}

/*!
 * \brief Reads a boolean value from the current stream and advances the current position of the stream by one byte.
 * \sa BitReader
 */
inline void BinaryReader::read(bool &oneBool)
{
    oneBool = readBool();
}

/*!
 * \brief Reads a length prefixed string from the current stream.
 *
 * \remarks Reads the length prefix from the stream and then a string of the denoted length.
 *          Advances the current position of the stream by the denoted length of the string plus the prefix length.
 */
inline void BinaryReader::read(std::string &lengthPrefixedString)
{
    lengthPrefixedString = readLengthPrefixedString();
}

/*!
 * \brief Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryReader::read(std::int16_t &one16BitInt)
{
    one16BitInt = readInt16BE();
}

/*!
 * \brief Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryReader::read(std::uint16_t &one16BitUInt)
{
    one16BitUInt = readUInt16BE();
}

/*!
 * \brief Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryReader::read(std::int32_t &one32BitInt)
{
    one32BitInt = readInt32BE();
}

/*!
 * \brief Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryReader::read(std::uint32_t &one32BitUInt)
{
    one32BitUInt = readUInt32BE();
}

/*!
 * \brief Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryReader::read(std::int64_t &one64BitInt)
{
    one64BitInt = readInt64BE();
}

/*!
 * \brief Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryReader::read(std::uint64_t &one64BitUInt)
{
    one64BitUInt = readUInt64BE();
}

/*!
 * \brief Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryReader::read(float &one32BitFloat)
{
    one32BitFloat = readFloat32BE();
}

/*!
 * \brief Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryReader::read(double &one64BitFloat)
{
    one64BitFloat = readFloat64BE();
}
} // namespace CppUtilities

#endif // IOUTILITIES_BINERYREADER_H