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. --- includes/Handle.h | 10 +++++++++- src/Handle.cc | 29 +++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/includes/Handle.h b/includes/Handle.h index 941748e..29cdb08 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -72,7 +72,15 @@ class Handle { Future readI16(); Future readI32(); Future readI64(); - Future writeU8 (uint8_t); + Future readBEU8(); + Future readBEU16(); + Future readBEU32(); + Future readBEU64(); + Future readBEI8(); + Future readBEI16(); + Future readBEI32(); + Future readBEI64(); + Future writeU8(uint8_t); Future writeU16(uint16_t); Future writeU32(uint32_t); Future writeU64(uint64_t); 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 040039e3007ea9a24621ea1831b51a516003ad64 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 19 Dec 2013 15:35:13 -0800 Subject: Adding the ability to mute the core engine even in debug builds. --- includes/Printer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Printer.h b/includes/Printer.h index d0eeab7..2717a84 100644 --- a/includes/Printer.h +++ b/includes/Printer.h @@ -65,7 +65,7 @@ class Printer { static void print(const char * fmt, ...) printfwarning(1, 2) { va_list ap; va_start(ap, fmt); vprint(fmt, ap); va_end(ap); } static void vprint(const char * fmt, va_list ap) printfwarning(1, 0) { getPrinter()->_print(fmt, ap); } -#ifdef DEBUG +#ifdef FULLDEBUG static void elog(uint32_t engine, const char * fmt, ...) printfwarning(2, 3) { va_list ap; va_start(ap, fmt); getPrinter()->_log(M_ENGINE_DEBUG, fmt, ap); } #else static void elog(uint32_t engine, const char * fmt, ...) { } -- 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(-) 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