diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-06-23 18:07:42 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-06-23 18:07:42 +0200 |
| commit | a7bcede17b4c10e172c7877fc2ce89862dc454af (patch) | |
| tree | d89b8ff274d18d67d695c5f320a1d079e1bb26b6 /le/le_entry_table_entry.cpp | |
| parent | 0f2d7c9ed9dfa3716840fc112bd53e5ec6b6315b (diff) | |
| download | openwar-a7bcede17b4c10e172c7877fc2ce89862dc454af.tar.gz openwar-a7bcede17b4c10e172c7877fc2ce89862dc454af.tar.bz2 openwar-a7bcede17b4c10e172c7877fc2ce89862dc454af.zip | |
adds alot more binary parsing.
Diffstat (limited to 'le/le_entry_table_entry.cpp')
| -rw-r--r-- | le/le_entry_table_entry.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
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 <boost/fusion/adapted/struct.hpp> + +typedef boost::variant<binparse::Offset16, binparse::Offset32> 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<le::EntryPoint>, entries) +) + +namespace le { + +EntryTableEntry parse_entry_table_entry(std::istream& is) { + EntryTableEntry entry; + + entry.nr_entries = binparse::parse<binparse::Value8>(is, "nr_entries"); + entry.flags = binparse::parse<binparse::Value8>(is, "flags"); + entry.object_index = binparse::parse<binparse::Value16>(is, "object_index"); + + for(Value8 i = Value8(0); i < entry.nr_entries; i++) { + if(entry.flags & 2) { + entry.entries.push_back({ + binparse::parse<Value8>(is, "flags"), + binparse::parse<Offset32>(is, "entry") + }); + } else { + entry.entries.push_back({ + binparse::parse<Value8>(is, "flags"), + binparse::parse<Offset16>(is, "entry") + }); + } + } + + return entry; +} + +std::ostream&operator<<(std::ostream& os, const EntryTableEntry& entry) +{ + return binparse::operator<<(os, entry); +} + +}
\ No newline at end of file |
