From a1d08fd27ab73b1697039e086d745ac68b890634 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 19 Dec 2013 15:32:43 -0800 Subject: Adding BigEndian reads. --- src/Handle.cc | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Handle.cc b/src/Handle.cc index 3b40c84..e6c0777 100644 --- a/src/Handle.cc +++ b/src/Handle.cc @@ -106,14 +106,30 @@ Balau::Future genericRead(Balau::IO t) { int c = 0; return Balau::Future([t, b, c]() mutable { do { - int r = t->read(((uint8_t *) b.get()) + c, sizeof(T)); + int r = t->read(((uint8_t *) b.get()) + c, sizeof(T) - c); c += r; } while (c < sizeof(T)); return *b; }); } -Balau::Future Balau::Handle::readU8 () { return genericRead(this); } +template +Balau::Future genericReadBE(Balau::IO t) { + std::shared_ptr b(new T); + int c = 0; + *b.get() = 0; + return Balau::Future([t, b, c]() mutable { + do { + uint8_t v = t->readU8().get(); + *b.get() <<= 8; + *b.get() += v; + c++; + } while (c < sizeof(T)); + return *b; + }); +} + +Balau::Future Balau::Handle::readU8() { return genericRead (this); } Balau::Future Balau::Handle::readU16() { return genericRead(this); } Balau::Future Balau::Handle::readU32() { return genericRead(this); } Balau::Future Balau::Handle::readU64() { return genericRead(this); } @@ -122,6 +138,15 @@ Balau::Future Balau::Handle::readI16() { return genericRead ( Balau::Future Balau::Handle::readI32() { return genericRead (this); } Balau::Future Balau::Handle::readI64() { return genericRead (this); } +Balau::Future Balau::Handle::readBEU8() { return genericReadBE (this); } +Balau::Future Balau::Handle::readBEU16() { return genericReadBE(this); } +Balau::Future Balau::Handle::readBEU32() { return genericReadBE(this); } +Balau::Future Balau::Handle::readBEU64() { return genericReadBE(this); } +Balau::Future Balau::Handle::readBEI8() { return genericReadBE (this); } +Balau::Future Balau::Handle::readBEI16() { return genericReadBE (this); } +Balau::Future Balau::Handle::readBEI32() { return genericReadBE (this); } +Balau::Future Balau::Handle::readBEI64() { return genericReadBE (this); } + template Balau::Future genericWrite(Balau::IO t, T val) { std::shared_ptr b(new T(val)); -- cgit v1.2.3 From 367ba1df2786888451328416a2db991fa8018083 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 19 Dec 2013 16:54:13 -0800 Subject: Fixing Win32's Input open statement. --- src/Input.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Input.cc b/src/Input.cc index 2a87a5d..64a05ec 100644 --- a/src/Input.cc +++ b/src/Input.cc @@ -40,7 +40,7 @@ class AsyncOpOpen : public Balau::AsyncOperation { AsyncOpOpen(const char * path, cbResults_t * results) : m_path(path), m_results(results) { } virtual void run() { #ifdef _MSC_VER - const ssize_t r = m_results->result = _open(m_path, O_RDONLY); + const ssize_t r = m_results->result = _open(m_path, O_RDONLY | O_BINARY); #else const ssize_t r = m_results->result = open(m_path, O_RDONLY); #endif -- cgit v1.2.3