diff options
-rw-r--r-- | includes/Handle.h | 10 | ||||
-rw-r--r-- | includes/Printer.h | 2 | ||||
-rw-r--r-- | src/Handle.cc | 29 | ||||
-rw-r--r-- | src/Input.cc | 2 |
4 files changed, 38 insertions, 5 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<int16_t> readI16(); Future<int32_t> readI32(); Future<int64_t> readI64(); - Future<void> writeU8 (uint8_t); + Future<uint8_t> readBEU8(); + Future<uint16_t> readBEU16(); + Future<uint32_t> readBEU32(); + Future<uint64_t> readBEU64(); + Future<int8_t> readBEI8(); + Future<int16_t> readBEI16(); + Future<int32_t> readBEI32(); + Future<int64_t> readBEI64(); + Future<void> writeU8(uint8_t); Future<void> writeU16(uint16_t); Future<void> writeU32(uint32_t); Future<void> writeU64(uint64_t); 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, ...) { } 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<T> genericRead(Balau::IO<Balau::Handle> t) { int c = 0; return Balau::Future<T>([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<uint8_t> Balau::Handle::readU8 () { return genericRead<uint8_t >(this); } +template<class T> +Balau::Future<T> genericReadBE(Balau::IO<Balau::Handle> t) { + std::shared_ptr<T> b(new T); + int c = 0; + *b.get() = 0; + return Balau::Future<T>([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<uint8_t> Balau::Handle::readU8() { return genericRead<uint8_t> (this); } Balau::Future<uint16_t> Balau::Handle::readU16() { return genericRead<uint16_t>(this); } Balau::Future<uint32_t> Balau::Handle::readU32() { return genericRead<uint32_t>(this); } Balau::Future<uint64_t> Balau::Handle::readU64() { return genericRead<uint64_t>(this); } @@ -122,6 +138,15 @@ Balau::Future<int16_t> Balau::Handle::readI16() { return genericRead<int16_t> ( Balau::Future<int32_t> Balau::Handle::readI32() { return genericRead<int32_t> (this); } Balau::Future<int64_t> Balau::Handle::readI64() { return genericRead<int64_t> (this); } +Balau::Future<uint8_t> Balau::Handle::readBEU8() { return genericReadBE<uint8_t> (this); } +Balau::Future<uint16_t> Balau::Handle::readBEU16() { return genericReadBE<uint16_t>(this); } +Balau::Future<uint32_t> Balau::Handle::readBEU32() { return genericReadBE<uint32_t>(this); } +Balau::Future<uint64_t> Balau::Handle::readBEU64() { return genericReadBE<uint64_t>(this); } +Balau::Future<int8_t> Balau::Handle::readBEI8() { return genericReadBE<int8_t> (this); } +Balau::Future<int16_t> Balau::Handle::readBEI16() { return genericReadBE<int16_t> (this); } +Balau::Future<int32_t> Balau::Handle::readBEI32() { return genericReadBE<int32_t> (this); } +Balau::Future<int64_t> Balau::Handle::readBEI64() { return genericReadBE<int64_t> (this); } + template<class T> Balau::Future<void> genericWrite(Balau::IO<Balau::Handle> t, T val) { std::shared_ptr<T> b(new T(val)); 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 |