summaryrefslogtreecommitdiff
path: root/binparse
diff options
context:
space:
mode:
Diffstat (limited to 'binparse')
-rw-r--r--binparse/binparse.cpp45
-rw-r--r--binparse/binparse.hpp9
2 files changed, 54 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));
diff --git a/binparse/binparse.hpp b/binparse/binparse.hpp
index 1620ab5..5b21086 100644
--- a/binparse/binparse.hpp
+++ b/binparse/binparse.hpp
@@ -3,6 +3,7 @@
#include <string>
#include <ostream>
#include <iomanip>
+#include <vector>
namespace binparse {
@@ -39,6 +40,14 @@ Value32 parse<Value32>(std::istream& is, std::string name);
template<>
Offset32 parse<Offset32>(std::istream& is, std::string name);
+template<>
+std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::string name);
+
+template<>
+std::array<uint8_t, 22> parse<std::array<uint8_t, 22>>(std::istream& is, std::string name);
+
+void dump_bytes(std::istream& is, std::vector<uint8_t> buffer, std::string name);
+
std::string to_string(Magic16 magic);
//overload inside this namespace to output unsigned char as value not as characters.