diff options
Diffstat (limited to 'binparse/binparse.cpp')
| -rw-r--r-- | binparse/binparse.cpp | 45 |
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)); |
