From a37749140585cd76178a93faf3abd27cd2fc30dc Mon Sep 17 00:00:00 2001 From: Casey Dahlin Date: Thu, 15 Oct 2015 15:44:59 -0700 Subject: [PATCH] Add methods to Parcel for bool and char and byte We lift these to int, but handling the details of that here will be better than having AIDL generate casting code all the time. Test: unit tests pass Bug: 24981507 Signed-off-by: Casey Dahlin (cherry picked from commit d6848f52e60be17b7f0992be7827dcae4ea2efb1) Change-Id: I471586463360c37e837b1b8f862da3b5e17f905d --- include/binder/Parcel.h | 9 +++++++++ libs/binder/Parcel.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 16cd6cf678..981af2f1fc 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -108,6 +108,9 @@ public: status_t writeWeakBinder(const wp& val); status_t writeInt32Array(size_t len, const int32_t *val); status_t writeByteArray(size_t len, const uint8_t *val); + status_t writeBool(bool val); + status_t writeChar(char16_t val); + status_t writeByte(int8_t val); template status_t write(const Flattenable& val); @@ -169,6 +172,12 @@ public: status_t readDouble(double *pArg) const; intptr_t readIntPtr() const; status_t readIntPtr(intptr_t *pArg) const; + bool readBool() const; + status_t readBool(bool *pArg) const; + char16_t readChar() const; + status_t readChar(char16_t *pArg) const; + int8_t readByte() const; + status_t readByte(int8_t *pArg) const; const char* readCString() const; String8 readString8() const; diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 7e2f0d034e..a4c5ada422 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -786,6 +786,21 @@ status_t Parcel::writeByteArray(size_t len, const uint8_t *val) { return ret; } +status_t Parcel::writeBool(bool val) +{ + return writeInt32(int32_t(val)); +} + +status_t Parcel::writeChar(char16_t val) +{ + return writeInt32(int32_t(val)); +} + +status_t Parcel::writeByte(int8_t val) +{ + return writeInt32(int32_t(val)); +} + status_t Parcel::writeInt64(int64_t val) { return writeAligned(val); @@ -1276,6 +1291,44 @@ intptr_t Parcel::readIntPtr() const return readAligned(); } +status_t Parcel::readBool(bool *pArg) const +{ + int32_t tmp; + status_t ret = readInt32(&tmp); + *pArg = (tmp != 0); + return ret; +} + +bool Parcel::readBool() const +{ + return readInt32() != 0; +} + +status_t Parcel::readChar(char16_t *pArg) const +{ + int32_t tmp; + status_t ret = readInt32(&tmp); + *pArg = char16_t(tmp); + return ret; +} + +char16_t Parcel::readChar() const +{ + return char16_t(readInt32()); +} + +status_t Parcel::readByte(int8_t *pArg) const +{ + int32_t tmp; + status_t ret = readInt32(&tmp); + *pArg = int8_t(tmp); + return ret; +} + +int8_t Parcel::readByte() const +{ + return int8_t(readInt32()); +} const char* Parcel::readCString() const { -- 2.11.0