From a7bcede17b4c10e172c7877fc2ce89862dc454af Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Thu, 23 Jun 2016 18:07:42 +0200 Subject: adds alot more binary parsing. --- le/le_entry_table_entry.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 le/le_entry_table_entry.cpp (limited to 'le/le_entry_table_entry.cpp') diff --git a/le/le_entry_table_entry.cpp b/le/le_entry_table_entry.cpp new file mode 100644 index 0000000..4894ec0 --- /dev/null +++ b/le/le_entry_table_entry.cpp @@ -0,0 +1,55 @@ +#include "le_entry_table_entry.hpp" + +#include "parse.hpp" +#include "output.hpp" + +#include + +typedef boost::variant EntryT; + +BOOST_FUSION_ADAPT_STRUCT( + le::EntryPoint, + (binparse::Value8, flags) + (EntryT, entry) +) + +BOOST_FUSION_ADAPT_STRUCT( + le::EntryTableEntry, + (binparse::Value8, nr_entries) + (binparse::Value8, flags) + (binparse::Value16, object_index) + (std::vector, entries) +) + +namespace le { + +EntryTableEntry parse_entry_table_entry(std::istream& is) { + EntryTableEntry entry; + + entry.nr_entries = binparse::parse(is, "nr_entries"); + entry.flags = binparse::parse(is, "flags"); + entry.object_index = binparse::parse(is, "object_index"); + + for(Value8 i = Value8(0); i < entry.nr_entries; i++) { + if(entry.flags & 2) { + entry.entries.push_back({ + binparse::parse(is, "flags"), + binparse::parse(is, "entry") + }); + } else { + entry.entries.push_back({ + binparse::parse(is, "flags"), + binparse::parse(is, "entry") + }); + } + } + + return entry; +} + +std::ostream&operator<<(std::ostream& os, const EntryTableEntry& entry) +{ + return binparse::operator<<(os, entry); +} + +} \ No newline at end of file -- cgit v1.2.3-70-g09d2