summaryrefslogtreecommitdiff
path: root/binparse/binparse.cpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-06-19 22:05:32 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-06-19 22:05:32 +0200
commitde95ca22ec87cc8b79ceb7beba475301461713a6 (patch)
treedce723a717ac0ba583de992777d7d968c3be870b /binparse/binparse.cpp
parentcea325b7451c1fb8dd22462ec2e7b5b88ea9b547 (diff)
downloadopenwar-de95ca22ec87cc8b79ceb7beba475301461713a6.tar.gz
openwar-de95ca22ec87cc8b79ceb7beba475301461713a6.tar.bz2
openwar-de95ca22ec87cc8b79ceb7beba475301461713a6.zip
adds an LE file parser and refactors some code.
Diffstat (limited to 'binparse/binparse.cpp')
-rw-r--r--binparse/binparse.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/binparse/binparse.cpp b/binparse/binparse.cpp
index 1dc4fc6..eae6143 100644
--- a/binparse/binparse.cpp
+++ b/binparse/binparse.cpp
@@ -90,6 +90,51 @@ Offset32 parse<Offset32>(std::istream& is, std::string name) {
return Offset32(parse<uint32_t>(is, name));
}
+template<>
+std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::string name) {
+ if(!is) {
+ throw UnexpectedEOS();
+ }
+
+ std::array<uint8_t, 8> buffer;
+ is.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
+
+ if(!is) {
+ throw UnexpectedEOS(name);
+ }
+
+ return buffer;
+}
+
+template<>
+std::array<uint8_t, 22> parse<std::array<uint8_t, 22>>(std::istream& is, std::string name) {
+ if(!is) {
+ throw UnexpectedEOS();
+ }
+
+ std::array<uint8_t, 22> buffer;
+ is.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
+
+ if(!is) {
+ throw UnexpectedEOS(name);
+ }
+
+ return buffer;
+}
+
+void dump_bytes(std::istream& is, std::vector<uint8_t>& buffer, std::string name)
+{
+ if(!is) {
+ throw UnexpectedEOS();
+ }
+
+ is.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
+
+ if(!is) {
+ throw UnexpectedEOS(name);
+ }
+}
+
std::string to_string(Magic16 magic) {
char* c = reinterpret_cast<char*>(&magic);
return std::string(c, sizeof(Magic16));