diff options
| author | 2016-08-19 23:14:50 +0000 | |
|---|---|---|
| committer | 2016-08-19 23:14:51 +0000 | |
| commit | b77d368d89849be01ef405b686ffd4886006181d (patch) | |
| tree | 07460bd1e1f86a75e8e9eda13191df0d39e09b7f | |
| parent | 5242fb42fbc110f349f9ce40e3e970fccc4d2673 (diff) | |
| parent | 31c1beb1d8de373f7734a54e25ad80b01024adb0 (diff) | |
Merge "libbinder: Support reading/writing out T[] lengths"
| -rw-r--r-- | include/binder/Parcel.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index fe3aed6213..7ee25dd19f 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -166,6 +166,10 @@ public: template<typename T> status_t write(const LightFlattenable<T>& val); + template<typename T> + status_t writeVectorSize(const std::vector<T>& val); + template<typename T> + status_t writeVectorSize(const std::unique_ptr<std::vector<T>>& val); // Place a native_handle into the parcel (the native_handle's file- // descriptors are dup'ed, so it is safe to delete the native_handle @@ -305,6 +309,11 @@ public: template<typename T> status_t read(LightFlattenable<T>& val) const; + template<typename T> + status_t resizeOutVector(std::vector<T>* val) const; + template<typename T> + status_t resizeOutVector(std::unique_ptr<std::vector<T>>* val) const; + // Like Parcel.java's readExceptionCode(). Reads the first int32 // off of a Parcel's header, returning 0 or the negative error // code on exceptions, but also deals with skipping over rich @@ -564,6 +573,54 @@ status_t Parcel::read(LightFlattenable<T>& val) const { } template<typename T> +status_t Parcel::writeVectorSize(const std::vector<T>& val) { + if (val.size() > INT32_MAX) { + return BAD_VALUE; + } + return writeInt32(val.size()); +} + +template<typename T> +status_t Parcel::writeVectorSize(const std::unique_ptr<std::vector<T>>& val) { + if (!val) { + return writeInt32(-1); + } + + return writeVectorSize(*val); +} + +template<typename T> +status_t Parcel::resizeOutVector(std::vector<T>* val) const { + int32_t size; + status_t err = readInt32(&size); + if (err != NO_ERROR) { + return err; + } + + if (size < 0) { + return UNEXPECTED_NULL; + } + val->resize(size_t(size)); + return OK; +} + +template<typename T> +status_t Parcel::resizeOutVector(std::unique_ptr<std::vector<T>>* val) const { + int32_t size; + status_t err = readInt32(&size); + if (err != NO_ERROR) { + return err; + } + + val->reset(); + if (size >= 0) { + val->reset(new std::vector<T>(size_t(size))); + } + + return OK; +} + +template<typename T> status_t Parcel::readStrongBinder(sp<T>* val) const { sp<IBinder> tmp; status_t ret = readStrongBinder(&tmp); |