From de95ca22ec87cc8b79ceb7beba475301461713a6 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sun, 19 Jun 2016 22:05:32 +0200 Subject: adds an LE file parser and refactors some code. --- binparse/binparse.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'binparse/binparse.cpp') 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(std::istream& is, std::string name) { return Offset32(parse(is, name)); } +template<> +std::array parse>(std::istream& is, std::string name) { + if(!is) { + throw UnexpectedEOS(); + } + + std::array buffer; + is.read(reinterpret_cast(buffer.data()), buffer.size()); + + if(!is) { + throw UnexpectedEOS(name); + } + + return buffer; +} + +template<> +std::array parse>(std::istream& is, std::string name) { + if(!is) { + throw UnexpectedEOS(); + } + + std::array buffer; + is.read(reinterpret_cast(buffer.data()), buffer.size()); + + if(!is) { + throw UnexpectedEOS(name); + } + + return buffer; +} + +void dump_bytes(std::istream& is, std::vector& buffer, std::string name) +{ + if(!is) { + throw UnexpectedEOS(); + } + + is.read(reinterpret_cast(buffer.data()), buffer.size()); + + if(!is) { + throw UnexpectedEOS(name); + } +} + std::string to_string(Magic16 magic) { char* c = reinterpret_cast(&magic); return std::string(c, sizeof(Magic16)); -- cgit v1.2.3-70-g09d2