File: binarywriter.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 (745 lines) | stat: -rw-r--r-- 25,252 bytes parent folder | download | duplicates (3)
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
739
740
741
742
743
744
745
#ifndef IOUTILITIES_BINARYWRITER_H
#define IOUTILITIES_BINARYWRITER_H

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

#include <cstdint>
#include <cstring>
#include <ostream>
#include <string>
#include <vector>

namespace CppUtilities {

class CPP_UTILITIES_EXPORT BinaryWriter {
public:
    BinaryWriter(std::ostream *stream, bool giveOwnership = false);
    BinaryWriter(const BinaryWriter &other);
    BinaryWriter &operator=(const BinaryWriter &rhs) = delete;
    ~BinaryWriter();

    const std::ostream *stream() const;
    std::ostream *stream();
    void setStream(std::ostream *stream, bool giveOwnership = false);
    bool hasOwnership() const;
    void giveOwnership();
    void detatchOwnership();
    void flush();
    bool fail() const;
    void write(const char *buffer, std::streamsize length);
    void write(const std::vector<char> &buffer, std::streamsize length);
    void writeChar(char value);
    void writeByte(std::uint8_t value);
    void writeInt16BE(std::int16_t value);
    void writeUInt16BE(std::uint16_t value);
    void writeInt24BE(std::int32_t value);
    void writeUInt24BE(std::uint32_t value);
    void writeInt32BE(std::int32_t value);
    void writeUInt32BE(std::uint32_t value);
    void writeInt40BE(std::int64_t value);
    void writeUInt40BE(std::uint64_t value);
    void writeInt56BE(std::int64_t value);
    void writeUInt56BE(std::uint64_t value);
    void writeInt64BE(std::int64_t value);
    void writeUInt64BE(std::uint64_t value);
    void writeVariableLengthUIntBE(std::uint64_t value);
    void writeFloat32BE(float value);
    void writeFloat64BE(double value);
    void writeInt16LE(std::int16_t value);
    void writeUInt16LE(std::uint16_t value);
    void writeInt24LE(std::int32_t value);
    void writeUInt24LE(std::uint32_t value);
    void writeInt32LE(std::int32_t value);
    void writeUInt32LE(std::uint32_t value);
    void writeInt40LE(std::int64_t value);
    void writeUInt40LE(std::uint64_t value);
    void writeInt56LE(std::int64_t value);
    void writeUInt56LE(std::uint64_t value);
    void writeInt64LE(std::int64_t value);
    void writeUInt64LE(std::uint64_t value);
    void writeVariableLengthUIntLE(std::uint64_t value);
    void writeFloat32LE(float value);
    void writeFloat64LE(double value);
    void writeString(const std::string &value);
    void writeTerminatedString(const std::string &value);
    void writeLengthPrefixedString(const std::string &value);
    void writeLengthPrefixedCString(const char *value, std::size_t size);
    void writeBool(bool value);
    void writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite);
    void writeFixed8BE(float valueToConvertAndWrite);
    void writeFixed16BE(float valueToConvertAndWrite);
    void writeSynchsafeUInt32LE(std::uint32_t valueToConvertAndWrite);
    void writeFixed8LE(float valueToConvertAndWrite);
    void writeFixed16LE(float valueToConvertAndWrite);

    // declare further overloads for write() to ease use of BinaryWriter in templates
    void write(char oneChar);
    void write(std::uint8_t oneByte);
    void write(bool oneBool);
    void write(const std::string &lengthPrefixedString);
    void write(std::string_view lengthPrefixedString);
    void write(const char *lengthPrefixedString);
    void write(std::int16_t one16BitInt);
    void write(std::uint16_t one16BitUint);
    void write(std::int32_t one32BitInt);
    void write(std::uint32_t one32BitUint);
    void write(std::int64_t one64BitInt);
    void write(std::uint64_t one64BitUint);
    void write(float one32BitFloat);
    void write(double one64BitFloat);

private:
    void writeVariableLengthInteger(std::uint64_t size, void (*getBytes)(std::uint64_t, char *));

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

/*!
 * \brief Constructs a new BinaryWriter.
 * \param stream Specifies the stream to write to.
 * \param giveOwnership Specifies whether the writer should take ownership.
 */
inline BinaryWriter::BinaryWriter(std::ostream *stream, bool giveOwnership)
    : m_stream(stream)
    , m_ownership(giveOwnership)
{
}

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

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

/*!
 * \brief Returns a pointer to the stream the writer will write to when calling one of the write-methods.
 *
 * \sa setStream()
 */
inline std::ostream *BinaryWriter::stream()
{
    return m_stream;
}

/*!
 * \brief Returns a pointer to the stream the writer will write to when calling one of the write-methods.
 *
 * \sa setStream()
 */
inline const std::ostream *BinaryWriter::stream() const
{
    return m_stream;
}

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

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

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

/*!
 * \brief Calls the flush() method of the assigned stream.
 */
inline void BinaryWriter::flush()
{
    m_stream->flush();
}

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

/*!
 * \brief Writes a character array to the current stream and advances the current position of the stream by the \a length of the array.
 */
inline void BinaryWriter::write(const char *buffer, std::streamsize length)
{
    m_stream->write(buffer, length);
}

/*!
 * \brief Writes the specified number of bytes from the \a buffer to the current stream and advances the current position of the stream by
 *        the specified \a length which must be less or equal to the \a buffer size.
 */
inline void BinaryWriter::write(const std::vector<char> &buffer, std::streamsize length)
{
    m_stream->write(buffer.data(), length);
}

/*!
 * \brief Writes a single character to the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryWriter::writeChar(char value)
{
    m_buffer[0] = value;
    m_stream->write(m_buffer, 1);
}

/*!
 * \brief Writes a single byte to the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryWriter::writeByte(std::uint8_t value)
{
    m_buffer[0] = *reinterpret_cast<char *>(&value);
    m_stream->write(m_buffer, 1);
}

/*!
 * \brief Writes a boolean value to the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryWriter::writeBool(bool value)
{
    writeByte(value ? 1 : 0);
}

/*!
 * \brief Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::writeInt16BE(std::int16_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::int16_t));
}

/*!
 * \brief Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::writeUInt16BE(std::uint16_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::uint16_t));
}

/*!
 * \brief Writes a 24-bit big endian signed integer to the current stream and advances the current position of the stream by three bytes.
 * \remarks The most significant byte of the specified 32-bit signed integer \a value will be discarded.
 */
inline void BinaryWriter::writeInt24BE(std::int32_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer + 1, 3);
}

/*!
 * \brief Writes a 24-bit big endian unsigned integer to the current stream and advances the current position of the stream by three bytes.
 * \remarks The most significant byte of the specified 32-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeUInt24BE(std::uint32_t value)
{
    // discard most significant byte
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer + 1, 3);
}

/*!
 * \brief Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeInt32BE(std::int32_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::int32_t));
}

/*!
 * \brief Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeUInt32BE(std::uint32_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::uint32_t));
}

/*!
 * \brief Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeInt40BE(std::int64_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer + 3, 5);
}

/*!
 * \brief Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeUInt40BE(std::uint64_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer + 3, 5);
}

/*!
 * \brief Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeInt56BE(std::int64_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer + 1, 7);
}

/*!
 * \brief Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeUInt56BE(std::uint64_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer + 1, 7);
}

/*!
 * \brief Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::writeInt64BE(std::int64_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::int64_t));
}

/*!
 * \brief Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::writeUInt64BE(std::uint64_t value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::uint64_t));
}

/*!
 * \brief Writes an up to 8 byte long big endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes.
 * \throws Throws ConversionException if \a value exceeds the maximum.
 */
inline void BinaryWriter::writeVariableLengthUIntBE(std::uint64_t value)
{
    writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&BE::getBytes));
}

/*!
 * \brief Writes a 32-bit big endian floating point \a value to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeFloat32BE(float value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(float));
}

/*!
 * \brief Writes a 64-bit big endian floating point \a value to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::writeFloat64BE(double value)
{
    BE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(double));
}

/*!
 * \brief Writes a 16-bit little endian signed integer to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::writeInt16LE(std::int16_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::int16_t));
}

/*!
 * \brief Writes a 16-bit little endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::writeUInt16LE(std::uint16_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::uint16_t));
}

/*!
 * \brief Writes a 24-bit little endian signed integer to the current stream and advances the current position of the stream by three bytes.
 * \remarks The most significant byte of the specified 32-bit signed integer \a value will be discarded.
 */
inline void BinaryWriter::writeInt24LE(std::int32_t value)
{
    // discard most significant byte
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, 3);
}

/*!
 * \brief Writes a 24-bit little endian unsigned integer to the current stream and advances the current position of the stream by three bytes.
 * \remarks The most significant byte of the specified 32-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeUInt24LE(std::uint32_t value)
{
    // discard most significant byte
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, 3);
}

/*!
 * \brief Writes a 32-bit little endian signed integer to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeInt32LE(std::int32_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::int32_t));
}

/*!
 * \brief Writes a 32-bit little endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeUInt32LE(std::uint32_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::uint32_t));
}

/*!
 * \brief Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeInt40LE(std::int64_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, 5);
}

/*!
 * \brief Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeUInt40LE(std::uint64_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, 5);
}

/*!
 * \brief Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeInt56LE(std::int64_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, 7);
}

/*!
 * \brief Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
 * \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
 */
inline void BinaryWriter::writeUInt56LE(std::uint64_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, 7);
}

/*!
 * \brief Writes a 64-bit little endian signed integer to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::writeInt64LE(std::int64_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::int64_t));
}

/*!
 * \brief Writes a 64-bit little endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::writeUInt64LE(std::uint64_t value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(std::uint64_t));
}

/*!
 * \brief Writes an up to 8 byte long little endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes.
 * \throws Throws ConversionException if \a value exceeds the maximum.
 */
inline void BinaryWriter::writeVariableLengthUIntLE(std::uint64_t value)
{
    writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&LE::getBytes));
}

/*!
 * \brief Writes a 32-bit little endian floating point \a value to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeFloat32LE(float value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(float));
}

/*!
 * \brief Writes a 64-bit little endian floating point \a value to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::writeFloat64LE(double value)
{
    LE::getBytes(value, m_buffer);
    m_stream->write(m_buffer, sizeof(double));
}

/*!
 * \brief Writes a string to the current stream and advances the current position of the stream by the length of the string.
 */
inline void BinaryWriter::writeString(const std::string &value)
{
    m_stream->write(value.data(), static_cast<std::streamsize>(value.size()));
}

/*!
 * \brief Writes a terminated string to the current stream and advances the current position of the stream by the length of the string plus 1.
 */
inline void BinaryWriter::writeTerminatedString(const std::string &value)
{
    m_stream->write(value.data(), static_cast<std::streamsize>(value.size() + 1));
}

/*!
 * \brief Writes the length of a string and the string itself to the current stream.
 *
 * Advances the current position of the stream by the length of the string plus the size of the length prefix.
 *
 * \throws Throws ConversionException if the string size exceeds the maximum.
 */
inline void BinaryWriter::writeLengthPrefixedString(const std::string &value)
{
    writeVariableLengthUIntBE(value.size());
    m_stream->write(value.data(), static_cast<std::streamsize>(value.size()));
}

/*!
 * \brief Writes the length of a string and the string itself to the current stream.
 *
 * Advances the current position of the stream by the length of the string plus the size of the length prefix.
 *
 * \throws Throws ConversionException if the string size exceeds the maximum.
 */
inline void BinaryWriter::writeLengthPrefixedCString(const char *value, std::size_t size)
{
    writeVariableLengthUIntBE(size);
    m_stream->write(value, static_cast<std::streamsize>(size));
}

/*!
 * \brief Writes a 32-bit big endian synchsafe integer to 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 void BinaryWriter::writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite)
{
    writeUInt32BE(toSynchsafeInt(valueToConvertAndWrite));
}

/*!
 * \brief Writes the 8.8 fixed point big endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::writeFixed8BE(float valueToConvertAndWrite)
{
    writeUInt16BE(toFixed8(valueToConvertAndWrite));
}

/*!
 * \brief Writes the 16.16 fixed point big endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeFixed16BE(float valueToConvertAndWrite)
{
    writeUInt32BE(toFixed16(valueToConvertAndWrite));
}

/*!
 * \brief Writes a 32-bit little endian synchsafe integer to 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 void BinaryWriter::writeSynchsafeUInt32LE(std::uint32_t valueToConvertAndWrite)
{
    writeUInt32LE(toSynchsafeInt(valueToConvertAndWrite));
}

/*!
 * \brief Writes the 8.8 fixed point little endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::writeFixed8LE(float valueToConvertAndWrite)
{
    writeUInt16LE(toFixed8(valueToConvertAndWrite));
}

/*!
 * \brief Writes the 16.16 fixed point little endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::writeFixed16LE(float valueToConvertAndWrite)
{
    writeUInt32LE(toFixed16(valueToConvertAndWrite));
}

/*!
 * \brief Writes a single character to the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryWriter::write(char oneChar)
{
    writeChar(oneChar);
}

/*!
 * \brief Writes a single byte to the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryWriter::write(std::uint8_t oneByte)
{
    writeByte(oneByte);
}

/*!
 * \brief Writes a boolean value to the current stream and advances the current position of the stream by one byte.
 */
inline void BinaryWriter::write(bool oneBool)
{
    writeBool(oneBool);
}

/*!
 * \brief Writes the length of a string and the string itself to the current stream.
 *
 * Advances the current position of the stream by the length of the string plus the size of the length prefix.
 */
inline void BinaryWriter::write(const std::string &lengthPrefixedString)
{
    writeLengthPrefixedString(lengthPrefixedString);
}

/*!
 * \brief Writes the length of a string and the string itself to the current stream.
 *
 * Advances the current position of the stream by the length of the string plus the size of the length prefix.
 */
inline void BinaryWriter::write(std::string_view lengthPrefixedString)
{
    writeLengthPrefixedCString(lengthPrefixedString.data(), lengthPrefixedString.size());
}

/*!
 * \brief Writes the length of a string and the string itself to the current stream.
 *
 * Advances the current position of the stream by the length of the string plus the size of the length prefix.
 */
inline void BinaryWriter::write(const char *lengthPrefixedString)
{
    writeLengthPrefixedCString(lengthPrefixedString, std::strlen(lengthPrefixedString));
}

/*!
 * \brief Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::write(std::int16_t one16BitInt)
{
    writeInt16BE(one16BitInt);
}

/*!
 * \brief Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
 */
inline void BinaryWriter::write(std::uint16_t one16BitUint)
{
    writeUInt16BE(one16BitUint);
}

/*!
 * \brief Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::write(std::int32_t one32BitInt)
{
    writeInt32BE(one32BitInt);
}

/*!
 * \brief Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::write(std::uint32_t one32BitUint)
{
    writeUInt32BE(one32BitUint);
}

/*!
 * \brief Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::write(std::int64_t one64BitInt)
{
    writeInt64BE(one64BitInt);
}

/*!
 * \brief Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::write(std::uint64_t one64BitUint)
{
    writeUInt64BE(one64BitUint);
}

/*!
 * \brief Writes a 32-bit big endian floating point \a value to the current stream and advances the current position of the stream by four bytes.
 */
inline void BinaryWriter::write(float one32BitFloat)
{
    writeFloat32BE(one32BitFloat);
}

/*!
 * \brief Writes a 64-bit big endian floating point \a value to the current stream and advances the current position of the stream by eight bytes.
 */
inline void BinaryWriter::write(double one64BitFloat)
{
    writeFloat64BE(one64BitFloat);
}
} // namespace CppUtilities

#endif // IO_UTILITIES_BINARYWRITER_H