1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "tests/simple_parcelable.h" 18 19 #include <android-base/stringprintf.h> 20 #include <binder/Parcel.h> 21 #include <utils/String8.h> 22 23 using android::base::StringPrintf; 24 25 namespace android { 26 namespace aidl { 27 namespace tests { 28 29 SimpleParcelable::SimpleParcelable(const std::string& name, int32_t number) 30 : name_(name.c_str(), name.length()), 31 number_(number) {} 32 33 status_t SimpleParcelable::writeToParcel(Parcel* parcel) const { 34 status_t status = parcel->writeString16(name_); 35 if (status != OK) { 36 return status; 37 } 38 status = parcel->writeInt32(number_); 39 return status; 40 } 41 42 status_t SimpleParcelable::readFromParcel(const Parcel* parcel) { 43 status_t status = parcel->readString16(&name_); 44 if (status != OK) { 45 return status; 46 } 47 return parcel->readInt32(&number_); 48 } 49 50 std::string SimpleParcelable::toString() const { 51 return StringPrintf("%s(%d)", String8(name_).string(), number_); 52 } 53 54 } // namespace tests 55 } // namespace aidl 56 } // namespace android 57