aboutsummaryrefslogtreecommitdiff
path: root/common/stream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/stream.cpp')
-rw-r--r--common/stream.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/common/stream.cpp b/common/stream.cpp
index e151c058ce..11cce2a4cd 100644
--- a/common/stream.cpp
+++ b/common/stream.cpp
@@ -34,12 +34,24 @@ byte ReadStream::readByte() {
return b;
}
+int8 ReadStream::readSByte() {
+ int8 b = 0;
+ read(&b, 1);
+ return b;
+}
+
uint16 ReadStream::readUint16LE() {
uint16 a = readByte();
uint16 b = readByte();
return a | (b << 8);
}
+uint32 ReadStream::readUint24LE() {
+ uint32 a = readUint16LE();
+ uint32 b = readByte();
+ return (b << 16) | a;
+}
+
uint32 ReadStream::readUint32LE() {
uint32 a = readUint16LE();
uint32 b = readUint16LE();
@@ -52,6 +64,12 @@ uint16 ReadStream::readUint16BE() {
return a | (b << 8);
}
+uint32 ReadStream::readUint24BE() {
+ uint32 b = readByte();
+ uint32 a = readUint16BE();
+ return (b << 16) | a;
+}
+
uint32 ReadStream::readUint32BE() {
uint32 b = readUint16BE();
uint32 a = readUint16BE();
@@ -63,6 +81,10 @@ int16 ReadStream::readSint16LE() {
return (int16)readUint16LE();
}
+int32 ReadStream::readSint24LE() {
+ return (int32)readUint24LE();
+}
+
int32 ReadStream::readSint32LE() {
return (int32)readUint32LE();
}
@@ -71,6 +93,10 @@ int16 ReadStream::readSint16BE() {
return (int16)readUint16BE();
}
+int32 ReadStream::readSint24BE() {
+ return (int32)readUint24BE();
+}
+
int32 ReadStream::readSint32BE() {
return (int32)readUint32BE();
}
@@ -81,11 +107,20 @@ void WriteStream::writeByte(byte value) {
write(&value, 1);
}
+void WriteStream::writeSByte(int8 value) {
+ write(&value, 1);
+}
+
void WriteStream::writeUint16LE(uint16 value) {
writeByte((byte)(value & 0xff));
writeByte((byte)(value >> 8));
}
+void WriteStream::writeUint24LE(uint32 value) {
+ writeUint16LE((uint16)(value & 0xffff));
+ writeByte((byte)(value >> 16));
+}
+
void WriteStream::writeUint32LE(uint32 value) {
writeUint16LE((uint16)(value & 0xffff));
writeUint16LE((uint16)(value >> 16));
@@ -96,6 +131,11 @@ void WriteStream::writeUint16BE(uint16 value) {
writeByte((byte)(value & 0xff));
}
+void WriteStream::writeUint24BE(uint32 value) {
+ writeByte((byte)(value >> 16));
+ writeUint16BE((uint16)(value & 0xffff));
+}
+
void WriteStream::writeUint32BE(uint32 value) {
writeUint16BE((uint16)(value >> 16));
writeUint16BE((uint16)(value & 0xffff));
@@ -106,6 +146,10 @@ void WriteStream::writeSint16LE(int16 value) {
writeUint16LE((uint16)value);
}
+void WriteStream::writeSint24LE(int32 value) {
+ writeUint24LE((uint32)value);
+}
+
void WriteStream::writeSint32LE(int32 value) {
writeUint32LE((uint32)value);
}
@@ -114,6 +158,10 @@ void WriteStream::writeSint16BE(int16 value) {
writeUint16BE((uint16)value);
}
+void WriteStream::writeSint24BE(int32 value) {
+ writeUint24BE((uint32)value);
+}
+
void WriteStream::writeSint32BE(int32 value) {
writeUint32BE((uint32)value);
}