C++ Utilities  5.4.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
binarywriter.h
Go to the documentation of this file.
1 #ifndef IOUTILITIES_BINARYWRITER_H
2 #define IOUTILITIES_BINARYWRITER_H
3 
4 #include "../conversion/binaryconversion.h"
5 
6 #include <cstdint>
7 #include <cstring>
8 #include <ostream>
9 #include <string>
10 #include <vector>
11 
12 namespace CppUtilities {
13 
15 public:
16  BinaryWriter(std::ostream *stream, bool giveOwnership = false);
17  BinaryWriter(const BinaryWriter &other);
18  BinaryWriter &operator=(const BinaryWriter &rhs) = delete;
19  ~BinaryWriter();
20 
21  const std::ostream *stream() const;
22  std::ostream *stream();
23  void setStream(std::ostream *stream, bool giveOwnership = false);
24  bool hasOwnership() const;
25  void giveOwnership();
26  void detatchOwnership();
27  void flush();
28  bool fail() const;
29  void write(const char *buffer, std::streamsize length);
30  void write(const std::vector<char> &buffer, std::streamsize length);
31  void writeChar(char value);
32  void writeByte(std::uint8_t value);
33  void writeInt16BE(std::int16_t value);
34  void writeUInt16BE(std::uint16_t value);
35  void writeInt24BE(std::int32_t value);
36  void writeUInt24BE(std::uint32_t value);
37  void writeInt32BE(std::int32_t value);
38  void writeUInt32BE(std::uint32_t value);
39  void writeInt40BE(std::int64_t value);
40  void writeUInt40BE(std::uint64_t value);
41  void writeInt56BE(std::int64_t value);
42  void writeUInt56BE(std::uint64_t value);
43  void writeInt64BE(std::int64_t value);
44  void writeUInt64BE(std::uint64_t value);
45  void writeVariableLengthUIntBE(std::uint64_t value);
46  void writeFloat32BE(float value);
47  void writeFloat64BE(double value);
48  void writeInt16LE(std::int16_t value);
49  void writeUInt16LE(std::uint16_t value);
50  void writeInt24LE(std::int32_t value);
51  void writeUInt24LE(std::uint32_t value);
52  void writeInt32LE(std::int32_t value);
53  void writeUInt32LE(std::uint32_t value);
54  void writeInt40LE(std::int64_t value);
55  void writeUInt40LE(std::uint64_t value);
56  void writeInt56LE(std::int64_t value);
57  void writeUInt56LE(std::uint64_t value);
58  void writeInt64LE(std::int64_t value);
59  void writeUInt64LE(std::uint64_t value);
60  void writeVariableLengthUIntLE(std::uint64_t value);
61  void writeFloat32LE(float value);
62  void writeFloat64LE(double value);
63  void writeString(const std::string &value);
64  void writeTerminatedString(const std::string &value);
65  void writeLengthPrefixedString(const std::string &value);
66  void writeLengthPrefixedCString(const char *value, std::size_t size);
67  void writeBool(bool value);
68  void writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite);
69  void writeFixed8BE(float valueToConvertAndWrite);
70  void writeFixed16BE(float valueToConvertAndWrite);
71  void writeSynchsafeUInt32LE(std::uint32_t valueToConvertAndWrite);
72  void writeFixed8LE(float valueToConvertAndWrite);
73  void writeFixed16LE(float valueToConvertAndWrite);
74 
75  // declare further overloads for write() to ease use of BinaryWriter in templates
76  void write(char oneChar);
77  void write(std::uint8_t oneByte);
78  void write(bool oneBool);
79  void write(const std::string &lengthPrefixedString);
80  void write(const char *lengthPrefixedString);
81  void write(std::int16_t one16BitInt);
82  void write(std::uint16_t one16BitUint);
83  void write(std::int32_t one32BitInt);
84  void write(std::uint32_t one32BitUint);
85  void write(std::int64_t one64BitInt);
86  void write(std::uint64_t one64BitUint);
87  void write(float one32BitFloat);
88  void write(double one64BitFloat);
89 
90 private:
91  void writeVariableLengthInteger(std::uint64_t size, void (*getBytes)(std::uint64_t, char *));
92 
93  std::ostream *m_stream;
94  bool m_ownership;
95  char m_buffer[8];
96 };
97 
103 inline BinaryWriter::BinaryWriter(std::ostream *stream, bool giveOwnership)
104  : m_stream(stream)
105  , m_ownership(giveOwnership)
106 {
107 }
108 
114  : m_stream(other.m_stream)
115  , m_ownership(false)
116 {
117 }
118 
123 {
124  if (m_ownership) {
125  delete m_stream;
126  }
127 }
128 
134 inline std::ostream *BinaryWriter::stream()
135 {
136  return m_stream;
137 }
138 
144 inline const std::ostream *BinaryWriter::stream() const
145 {
146  return m_stream;
147 }
148 
156 inline bool BinaryWriter::hasOwnership() const
157 {
158  return m_ownership;
159 }
160 
169 {
170  if (m_stream) {
171  m_ownership = true;
172  }
173 }
174 
183 {
184  m_ownership = false;
185 }
186 
190 inline void BinaryWriter::flush()
191 {
192  m_stream->flush();
193 }
194 
198 inline bool BinaryWriter::fail() const
199 {
200  return m_stream ? m_stream->fail() : false;
201 }
202 
206 inline void BinaryWriter::write(const char *buffer, std::streamsize length)
207 {
208  m_stream->write(buffer, length);
209 }
210 
215 inline void BinaryWriter::write(const std::vector<char> &buffer, std::streamsize length)
216 {
217  m_stream->write(buffer.data(), length);
218 }
219 
223 inline void BinaryWriter::writeChar(char value)
224 {
225  m_buffer[0] = value;
226  m_stream->write(m_buffer, 1);
227 }
228 
232 inline void BinaryWriter::writeByte(std::uint8_t value)
233 {
234  m_buffer[0] = *reinterpret_cast<char *>(&value);
235  m_stream->write(m_buffer, 1);
236 }
237 
241 inline void BinaryWriter::writeBool(bool value)
242 {
243  writeByte(value ? 1 : 0);
244 }
245 
249 inline void BinaryWriter::writeInt16BE(std::int16_t value)
250 {
251  BE::getBytes(value, m_buffer);
252  m_stream->write(m_buffer, sizeof(std::int16_t));
253 }
254 
258 inline void BinaryWriter::writeUInt16BE(std::uint16_t value)
259 {
260  BE::getBytes(value, m_buffer);
261  m_stream->write(m_buffer, sizeof(std::uint16_t));
262 }
263 
268 inline void BinaryWriter::writeInt24BE(std::int32_t value)
269 {
270  BE::getBytes(value, m_buffer);
271  m_stream->write(m_buffer + 1, 3);
272 }
273 
278 inline void BinaryWriter::writeUInt24BE(std::uint32_t value)
279 {
280  // discard most significant byte
281  BE::getBytes(value, m_buffer);
282  m_stream->write(m_buffer + 1, 3);
283 }
284 
288 inline void BinaryWriter::writeInt32BE(std::int32_t value)
289 {
290  BE::getBytes(value, m_buffer);
291  m_stream->write(m_buffer, sizeof(std::int32_t));
292 }
293 
297 inline void BinaryWriter::writeUInt32BE(std::uint32_t value)
298 {
299  BE::getBytes(value, m_buffer);
300  m_stream->write(m_buffer, sizeof(std::uint32_t));
301 }
302 
307 inline void BinaryWriter::writeInt40BE(std::int64_t value)
308 {
309  BE::getBytes(value, m_buffer);
310  m_stream->write(m_buffer + 3, 5);
311 }
312 
317 inline void BinaryWriter::writeUInt40BE(std::uint64_t value)
318 {
319  BE::getBytes(value, m_buffer);
320  m_stream->write(m_buffer + 3, 5);
321 }
322 
327 inline void BinaryWriter::writeInt56BE(std::int64_t value)
328 {
329  BE::getBytes(value, m_buffer);
330  m_stream->write(m_buffer + 1, 7);
331 }
332 
337 inline void BinaryWriter::writeUInt56BE(std::uint64_t value)
338 {
339  BE::getBytes(value, m_buffer);
340  m_stream->write(m_buffer + 1, 7);
341 }
342 
346 inline void BinaryWriter::writeInt64BE(std::int64_t value)
347 {
348  BE::getBytes(value, m_buffer);
349  m_stream->write(m_buffer, sizeof(std::int64_t));
350 }
351 
355 inline void BinaryWriter::writeUInt64BE(std::uint64_t value)
356 {
357  BE::getBytes(value, m_buffer);
358  m_stream->write(m_buffer, sizeof(std::uint64_t));
359 }
360 
365 inline void BinaryWriter::writeVariableLengthUIntBE(std::uint64_t value)
366 {
367  writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&BE::getBytes));
368 }
369 
373 inline void BinaryWriter::writeFloat32BE(float value)
374 {
375  BE::getBytes(value, m_buffer);
376  m_stream->write(m_buffer, sizeof(float));
377 }
378 
382 inline void BinaryWriter::writeFloat64BE(double value)
383 {
384  BE::getBytes(value, m_buffer);
385  m_stream->write(m_buffer, sizeof(double));
386 }
387 
391 inline void BinaryWriter::writeInt16LE(std::int16_t value)
392 {
393  LE::getBytes(value, m_buffer);
394  m_stream->write(m_buffer, sizeof(std::int16_t));
395 }
396 
400 inline void BinaryWriter::writeUInt16LE(std::uint16_t value)
401 {
402  LE::getBytes(value, m_buffer);
403  m_stream->write(m_buffer, sizeof(std::uint16_t));
404 }
405 
410 inline void BinaryWriter::writeInt24LE(std::int32_t value)
411 {
412  // discard most significant byte
413  LE::getBytes(value, m_buffer);
414  m_stream->write(m_buffer, 3);
415 }
416 
421 inline void BinaryWriter::writeUInt24LE(std::uint32_t value)
422 {
423  // discard most significant byte
424  LE::getBytes(value, m_buffer);
425  m_stream->write(m_buffer, 3);
426 }
427 
431 inline void BinaryWriter::writeInt32LE(std::int32_t value)
432 {
433  LE::getBytes(value, m_buffer);
434  m_stream->write(m_buffer, sizeof(std::int32_t));
435 }
436 
440 inline void BinaryWriter::writeUInt32LE(std::uint32_t value)
441 {
442  LE::getBytes(value, m_buffer);
443  m_stream->write(m_buffer, sizeof(std::uint32_t));
444 }
445 
450 inline void BinaryWriter::writeInt40LE(std::int64_t value)
451 {
452  LE::getBytes(value, m_buffer);
453  m_stream->write(m_buffer, 5);
454 }
455 
460 inline void BinaryWriter::writeUInt40LE(std::uint64_t value)
461 {
462  LE::getBytes(value, m_buffer);
463  m_stream->write(m_buffer, 5);
464 }
465 
470 inline void BinaryWriter::writeInt56LE(std::int64_t value)
471 {
472  LE::getBytes(value, m_buffer);
473  m_stream->write(m_buffer, 7);
474 }
475 
480 inline void BinaryWriter::writeUInt56LE(std::uint64_t value)
481 {
482  LE::getBytes(value, m_buffer);
483  m_stream->write(m_buffer, 7);
484 }
485 
489 inline void BinaryWriter::writeInt64LE(std::int64_t value)
490 {
491  LE::getBytes(value, m_buffer);
492  m_stream->write(m_buffer, sizeof(std::int64_t));
493 }
494 
498 inline void BinaryWriter::writeUInt64LE(std::uint64_t value)
499 {
500  LE::getBytes(value, m_buffer);
501  m_stream->write(m_buffer, sizeof(std::uint64_t));
502 }
503 
508 inline void BinaryWriter::writeVariableLengthUIntLE(std::uint64_t value)
509 {
510  writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&LE::getBytes));
511 }
512 
516 inline void BinaryWriter::writeFloat32LE(float value)
517 {
518  LE::getBytes(value, m_buffer);
519  m_stream->write(m_buffer, sizeof(float));
520 }
521 
525 inline void BinaryWriter::writeFloat64LE(double value)
526 {
527  LE::getBytes(value, m_buffer);
528  m_stream->write(m_buffer, sizeof(double));
529 }
530 
534 inline void BinaryWriter::writeString(const std::string &value)
535 {
536  m_stream->write(value.c_str(), value.length());
537 }
538 
542 inline void BinaryWriter::writeTerminatedString(const std::string &value)
543 {
544  m_stream->write(value.c_str(), value.length() + 1);
545 }
546 
554 inline void BinaryWriter::writeLengthPrefixedString(const std::string &value)
555 {
556  writeVariableLengthUIntBE(value.size());
557  m_stream->write(value.data(), static_cast<std::streamsize>(value.size()));
558 }
559 
567 inline void BinaryWriter::writeLengthPrefixedCString(const char *value, std::size_t size)
568 {
570  m_stream->write(value, static_cast<std::streamsize>(size));
571 }
572 
578 inline void BinaryWriter::writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite)
579 {
580  writeUInt32BE(toSynchsafeInt(valueToConvertAndWrite));
581 }
582 
586 inline void BinaryWriter::writeFixed8BE(float valueToConvertAndWrite)
587 {
588  writeUInt16BE(toFixed8(valueToConvertAndWrite));
589 }
590 
594 inline void BinaryWriter::writeFixed16BE(float valueToConvertAndWrite)
595 {
596  writeUInt32BE(toFixed16(valueToConvertAndWrite));
597 }
598 
604 inline void BinaryWriter::writeSynchsafeUInt32LE(std::uint32_t valueToConvertAndWrite)
605 {
606  writeUInt32LE(toSynchsafeInt(valueToConvertAndWrite));
607 }
608 
612 inline void BinaryWriter::writeFixed8LE(float valueToConvertAndWrite)
613 {
614  writeUInt16LE(toFixed8(valueToConvertAndWrite));
615 }
616 
620 inline void BinaryWriter::writeFixed16LE(float valueToConvertAndWrite)
621 {
622  writeUInt32LE(toFixed16(valueToConvertAndWrite));
623 }
624 
628 inline void BinaryWriter::write(char oneChar)
629 {
630  writeChar(oneChar);
631 }
632 
636 inline void BinaryWriter::write(std::uint8_t oneByte)
637 {
638  writeByte(oneByte);
639 }
640 
644 inline void BinaryWriter::write(bool oneBool)
645 {
646  writeBool(oneBool);
647 }
648 
654 inline void BinaryWriter::write(const std::string &lengthPrefixedString)
655 {
656  writeLengthPrefixedCString(lengthPrefixedString.data(), lengthPrefixedString.size());
657 }
658 
664 inline void BinaryWriter::write(const char *lengthPrefixedString)
665 {
666  writeLengthPrefixedCString(lengthPrefixedString, std::strlen(lengthPrefixedString));
667 }
668 
672 inline void BinaryWriter::write(std::int16_t one16BitInt)
673 {
674  writeInt16BE(one16BitInt);
675 }
676 
680 inline void BinaryWriter::write(std::uint16_t one16BitUint)
681 {
682  writeUInt16BE(one16BitUint);
683 }
684 
688 inline void BinaryWriter::write(std::int32_t one32BitInt)
689 {
690  writeInt32BE(one32BitInt);
691 }
692 
696 inline void BinaryWriter::write(std::uint32_t one32BitUint)
697 {
698  writeUInt32BE(one32BitUint);
699 }
700 
704 inline void BinaryWriter::write(std::int64_t one64BitInt)
705 {
706  writeInt64BE(one64BitInt);
707 }
708 
712 inline void BinaryWriter::write(std::uint64_t one64BitUint)
713 {
714  writeUInt64BE(one64BitUint);
715 }
716 
720 inline void BinaryWriter::write(float one32BitFloat)
721 {
722  writeFloat32BE(one32BitFloat);
723 }
724 
728 inline void BinaryWriter::write(double one64BitFloat)
729 {
730  writeFloat64BE(one64BitFloat);
731 }
732 } // namespace CppUtilities
733 
734 #endif // IO_UTILITIES_BINARYWRITER_H
CppUtilities::BinaryWriter::writeInt16LE
void writeInt16LE(std::int16_t value)
Writes a 16-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:391
CppUtilities::BinaryWriter::writeChar
void writeChar(char value)
Writes a single character to the current stream and advances the current position of the stream by on...
Definition: binarywriter.h:223
CppUtilities::BinaryWriter::write
void write(const char *buffer, std::streamsize length)
Writes a character array to the current stream and advances the current position of the stream by the...
Definition: binarywriter.h:206
CppUtilities::BinaryWriter::writeInt64LE
void writeInt64LE(std::int64_t value)
Writes a 64-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:489
CppUtilities::toFixed16
constexpr CPP_UTILITIES_EXPORT std::uint32_t toFixed16(float float32value)
Returns the 16.16 fixed point representation converted from the specified 32-bit floating point numbe...
Definition: binaryconversion.h:117
CppUtilities::BinaryWriter::writeSynchsafeUInt32LE
void writeSynchsafeUInt32LE(std::uint32_t valueToConvertAndWrite)
Writes a 32-bit little endian synchsafe integer to the current stream and advances the current positi...
Definition: binarywriter.h:604
CppUtilities::BinaryWriter::writeBool
void writeBool(bool value)
Writes a boolean value to the current stream and advances the current position of the stream by one b...
Definition: binarywriter.h:241
CppUtilities::BinaryWriter::writeUInt32LE
void writeUInt32LE(std::uint32_t value)
Writes a 32-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:440
CppUtilities::BinaryWriter::writeUInt56LE
void writeUInt56LE(std::uint64_t value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:480
CppUtilities::BinaryWriter::writeUInt56BE
void writeUInt56BE(std::uint64_t value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:337
CppUtilities::BinaryWriter::detatchOwnership
void detatchOwnership()
The writer will not take ownership over the assigned stream.
Definition: binarywriter.h:182
CppUtilities::BinaryWriter::BinaryWriter
BinaryWriter(std::ostream *stream, bool giveOwnership=false)
Constructs a new BinaryWriter.
Definition: binarywriter.h:103
CppUtilities::BinaryWriter::writeInt16BE
void writeInt16BE(std::int16_t value)
Writes a 16-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:249
CppUtilities::BinaryWriter::writeVariableLengthUIntBE
void writeVariableLengthUIntBE(std::uint64_t value)
Writes an up to 8 byte long big endian unsigned integer to the current stream and advances the curren...
Definition: binarywriter.h:365
CppUtilities::BinaryWriter::writeUInt32BE
void writeUInt32BE(std::uint32_t value)
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:297
CppUtilities::BinaryWriter
Writes primitive data types to a std::ostream.
Definition: binarywriter.h:14
CppUtilities::BinaryWriter::writeInt40BE
void writeInt40BE(std::int64_t value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:307
CppUtilities::BinaryWriter::operator=
BinaryWriter & operator=(const BinaryWriter &rhs)=delete
CppUtilities::BinaryWriter::writeUInt64BE
void writeUInt64BE(std::uint64_t value)
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:355
CppUtilities::BinaryWriter::writeFloat32BE
void writeFloat32BE(float value)
Writes a 32-bit big endian floating point value to the current stream and advances the current positi...
Definition: binarywriter.h:373
CppUtilities::toFixed8
constexpr CPP_UTILITIES_EXPORT std::uint16_t toFixed8(float float32value)
Returns the 8.8 fixed point representation converted from the specified 32-bit floating point number.
Definition: binaryconversion.h:101
CppUtilities::BinaryWriter::~BinaryWriter
~BinaryWriter()
Destroys the BinaryWriter.
Definition: binarywriter.h:122
CppUtilities::BinaryWriter::writeInt24LE
void writeInt24LE(std::int32_t value)
Writes a 24-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:410
CppUtilities::BinaryWriter::writeInt56BE
void writeInt56BE(std::int64_t value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:327
CppUtilities::BinaryWriter::writeSynchsafeUInt32BE
void writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite)
Writes a 32-bit big endian synchsafe integer to the current stream and advances the current position ...
Definition: binarywriter.h:578
CppUtilities::BinaryWriter::writeUInt40BE
void writeUInt40BE(std::uint64_t value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:317
CppUtilities::BinaryWriter::writeFloat64LE
void writeFloat64LE(double value)
Writes a 64-bit little endian floating point value to the current stream and advances the current pos...
Definition: binarywriter.h:525
CppUtilities::BinaryWriter::writeTerminatedString
void writeTerminatedString(const std::string &value)
Writes a terminated string to the current stream and advances the current position of the stream by t...
Definition: binarywriter.h:542
CppUtilities::BinaryWriter::writeUInt64LE
void writeUInt64LE(std::uint64_t value)
Writes a 64-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:498
CppUtilities::BinaryWriter::writeInt40LE
void writeInt40LE(std::int64_t value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:450
CppUtilities::BinaryWriter::writeFixed8BE
void writeFixed8BE(float valueToConvertAndWrite)
Writes the 8.8 fixed point big endian representation for the specified 32-bit floating point value to...
Definition: binarywriter.h:586
CppUtilities::BinaryWriter::writeFixed16BE
void writeFixed16BE(float valueToConvertAndWrite)
Writes the 16.16 fixed point big endian representation for the specified 32-bit floating point value ...
Definition: binarywriter.h:594
CppUtilities::BinaryWriter::writeFixed16LE
void writeFixed16LE(float valueToConvertAndWrite)
Writes the 16.16 fixed point little endian representation for the specified 32-bit floating point val...
Definition: binarywriter.h:620
CppUtilities::BinaryWriter::writeVariableLengthUIntLE
void writeVariableLengthUIntLE(std::uint64_t value)
Writes an up to 8 byte long little endian unsigned integer to the current stream and advances the cur...
Definition: binarywriter.h:508
CppUtilities::BinaryWriter::fail
bool fail() const
Returns an indication whether the fail bit of the assigned stream is set.
Definition: binarywriter.h:198
CppUtilities::BinaryWriter::writeFloat32LE
void writeFloat32LE(float value)
Writes a 32-bit little endian floating point value to the current stream and advances the current pos...
Definition: binarywriter.h:516
CppUtilities::toSynchsafeInt
constexpr CPP_UTILITIES_EXPORT std::uint32_t toSynchsafeInt(std::uint32_t normalInt)
Returns a 32-bit synchsafe integer converted from a normal 32-bit integer.
Definition: binaryconversion.h:135
CppUtilities
Contains all utilities provides by the c++utilities library.
Definition: argumentparser.h:17
CppUtilities::BinaryWriter::writeString
void writeString(const std::string &value)
Writes a string to the current stream and advances the current position of the stream by the length o...
Definition: binarywriter.h:534
CppUtilities::BinaryWriter::writeUInt16LE
void writeUInt16LE(std::uint16_t value)
Writes a 16-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:400
CppUtilities::BinaryWriter::writeFloat64BE
void writeFloat64BE(double value)
Writes a 64-bit big endian floating point value to the current stream and advances the current positi...
Definition: binarywriter.h:382
CppUtilities::BinaryWriter::writeUInt40LE
void writeUInt40LE(std::uint64_t value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:460
CppUtilities::BinaryWriter::writeUInt16BE
void writeUInt16BE(std::uint16_t value)
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:258
CppUtilities::BinaryWriter::giveOwnership
void giveOwnership()
The writer will take ownership over the assigned stream.
Definition: binarywriter.h:168
CppUtilities::BinaryWriter::writeFixed8LE
void writeFixed8LE(float valueToConvertAndWrite)
Writes the 8.8 fixed point little endian representation for the specified 32-bit floating point value...
Definition: binarywriter.h:612
CppUtilities::BinaryWriter::writeUInt24LE
void writeUInt24LE(std::uint32_t value)
Writes a 24-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:421
CppUtilities::BinaryWriter::writeInt24BE
void writeInt24BE(std::int32_t value)
Writes a 24-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:268
CppUtilities::BinaryWriter::writeUInt24BE
void writeUInt24BE(std::uint32_t value)
Writes a 24-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:278
CppUtilities::BinaryWriter::writeByte
void writeByte(std::uint8_t value)
Writes a single byte to the current stream and advances the current position of the stream by one byt...
Definition: binarywriter.h:232
CppUtilities::BinaryWriter::writeInt56LE
void writeInt56LE(std::int64_t value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:470
CppUtilities::BinaryWriter::stream
const std::ostream * stream() const
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
Definition: binarywriter.h:144
CPP_UTILITIES_EXPORT
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
CppUtilities::BinaryWriter::flush
void flush()
Calls the flush() method of the assigned stream.
Definition: binarywriter.h:190
CppUtilities::BinaryWriter::writeLengthPrefixedString
void writeLengthPrefixedString(const std::string &value)
Writes the length of a string and the string itself to the current stream.
Definition: binarywriter.h:554
CppUtilities::BinaryWriter::writeLengthPrefixedCString
void writeLengthPrefixedCString(const char *value, std::size_t size)
Writes the length of a string and the string itself to the current stream.
Definition: binarywriter.h:567
CppUtilities::BinaryWriter::writeInt32LE
void writeInt32LE(std::int32_t value)
Writes a 32-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:431
CppUtilities::BinaryWriter::hasOwnership
bool hasOwnership() const
Returns whether the writer takes ownership over the assigned stream.
Definition: binarywriter.h:156
CppUtilities::BinaryWriter::writeInt64BE
void writeInt64BE(std::int64_t value)
Writes a 64-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:346
CppUtilities::BinaryWriter::writeInt32BE
void writeInt32BE(std::int32_t value)
Writes a 32-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:288