summaryrefslogtreecommitdiff
path: root/binparse/parse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'binparse/parse.cpp')
-rw-r--r--binparse/parse.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/binparse/parse.cpp b/binparse/parse.cpp
index a26e72e..de0f04d 100644
--- a/binparse/parse.cpp
+++ b/binparse/parse.cpp
@@ -80,6 +80,12 @@ Offset16 parse<Offset16>(std::istream& is, std::string name) {
}
template<>
+Value24 parse<Value24>(std::istream& is, std::__cxx11::string name)
+{
+ return Value24(parse<std::array<uint8_t, 3>>(is, name));
+}
+
+template<>
Value32 parse<Value32>(std::istream& is, std::string name) {
return Value32(parse<uint32_t>(is, name));
}
@@ -97,13 +103,13 @@ PString8 parse<PString8>(std::istream& is, std::string name) {
return PString8(std::string(data.begin(), data.end()));
}
-template<>
-std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::string name) {
+template<typename T, unsigned int N>
+std::array<T, N> parse(std::istream& is, std::string name) {
if(!is) {
throw UnexpectedEOS();
}
- std::array<uint8_t, 8> buffer;
+ std::array<T, N> buffer;
is.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
if(!is) {
@@ -114,19 +120,18 @@ std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::stri
}
template<>
+std::array<uint8_t, 3> parse<std::array<uint8_t, 3>>(std::istream& is, std::string name) {
+ return parse<uint8_t, 3>(is, name);
+}
+
+template<>
+std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::string name) {
+ return parse<uint8_t, 8>(is, name);
+}
+
+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;
+ return parse<uint8_t, 22>(is, name);
}
void dump_bytes(std::istream& is, std::vector<uint8_t>& buffer, std::string name)