summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-07-28 17:22:09 +0200
committerljfa-ag <ljfa-ag@web.de>2015-07-28 20:26:54 +0200
commita5bf6ccebd957365a4eeaa761688d44bfedb0593 (patch)
tree1d72e4341e06183c9ea1d9b13964318f6e15f6d5 /include
parentaeab493a5619b578bd0f2ea8e1e968a30bceb35f (diff)
downloadProject-Tick-a5bf6ccebd957365a4eeaa761688d44bfedb0593.tar.gz
Project-Tick-a5bf6ccebd957365a4eeaa761688d44bfedb0593.zip
Create endian_str.h and test
Diffstat (limited to 'include')
-rw-r--r--include/endian_str.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/include/endian_str.h b/include/endian_str.h
new file mode 100644
index 0000000000..f636773c12
--- /dev/null
+++ b/include/endian_str.h
@@ -0,0 +1,83 @@
+/*
+ * libnbt++ - A library for the Minecraft Named Binary Tag format.
+ * Copyright (C) 2013, 2015 ljfa-ag
+ *
+ * This file is part of libnbt++.
+ *
+ * libnbt++ is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libnbt++ is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libnbt++. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef ENDIAN_STR_H_INCLUDED
+#define ENDIAN_STR_H_INCLUDED
+
+#include <cstdint>
+#include <iosfwd>
+
+/**
+ * @brief Reading and writing numbers from and to streams
+ * in binary format with different byte orders.
+ */
+namespace endian
+{
+
+///Reads number from stream in little endian
+void read_little(std::istream& str, uint8_t& x);
+void read_little(std::istream& str, uint16_t& x);
+void read_little(std::istream& str, uint32_t& x);
+void read_little(std::istream& str, uint64_t& x);
+void read_little(std::istream& str, int8_t& x);
+void read_little(std::istream& str, int16_t& x);
+void read_little(std::istream& str, int32_t& x);
+void read_little(std::istream& str, int64_t& x);
+void read_little(std::istream& str, float& x);
+void read_little(std::istream& str, double& x);
+
+///Writes number to stream in little endian
+void write_little(std::ostream& str, uint8_t x);
+void write_little(std::ostream& str, uint16_t x);
+void write_little(std::ostream& str, uint32_t x);
+void write_little(std::ostream& str, uint64_t x);
+void write_little(std::ostream& str, int8_t x);
+void write_little(std::ostream& str, int16_t x);
+void write_little(std::ostream& str, int32_t x);
+void write_little(std::ostream& str, int64_t x);
+void write_little(std::ostream& str, float x);
+void write_little(std::ostream& str, double x);
+
+///Reads number from stream in big endian
+void read_big(std::istream& str, uint8_t& x);
+void read_big(std::istream& str, uint16_t& x);
+void read_big(std::istream& str, uint32_t& x);
+void read_big(std::istream& str, uint64_t& x);
+void read_big(std::istream& str, int8_t& x);
+void read_big(std::istream& str, int16_t& x);
+void read_big(std::istream& str, int32_t& x);
+void read_big(std::istream& str, int64_t& x);
+void read_big(std::istream& str, float& x);
+void read_big(std::istream& str, double& x);
+
+///Writes number to stream in big endian
+void write_big(std::ostream& str, uint8_t x);
+void write_big(std::ostream& str, uint16_t x);
+void write_big(std::ostream& str, uint32_t x);
+void write_big(std::ostream& str, uint64_t x);
+void write_big(std::ostream& str, int8_t x);
+void write_big(std::ostream& str, int16_t x);
+void write_big(std::ostream& str, int32_t x);
+void write_big(std::ostream& str, int64_t x);
+void write_big(std::ostream& str, float x);
+void write_big(std::ostream& str, double x);
+
+}
+
+#endif // ENDIAN_STR_H_INCLUDED