1996775af841578ead235540eb383f114b4e0eb00Christopher Wiley/* 2996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * Copyright (C) 2015 The Android Open Source Project 3996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * 4996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * Licensed under the Apache License, Version 2.0 (the "License"); 5996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * you may not use this file except in compliance with the License. 6996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * You may obtain a copy of the License at 7996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * 8996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * http://www.apache.org/licenses/LICENSE-2.0 9996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * 10996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * Unless required by applicable law or agreed to in writing, software 11996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * distributed under the License is distributed on an "AS IS" BASIS, 12996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * See the License for the specific language governing permissions and 14996775af841578ead235540eb383f114b4e0eb00Christopher Wiley * limitations under the License. 15996775af841578ead235540eb383f114b4e0eb00Christopher Wiley */ 16996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 17996775af841578ead235540eb383f114b4e0eb00Christopher Wiley#include "tests/simple_parcelable.h" 18996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 190a62067f35e957493bc37c4b42dfdcfc16353831Elliott Hughes#include <android-base/stringprintf.h> 20996775af841578ead235540eb383f114b4e0eb00Christopher Wiley#include <binder/Parcel.h> 21996775af841578ead235540eb383f114b4e0eb00Christopher Wiley#include <utils/String8.h> 22996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 23996775af841578ead235540eb383f114b4e0eb00Christopher Wileyusing android::base::StringPrintf; 24996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 25996775af841578ead235540eb383f114b4e0eb00Christopher Wileynamespace android { 26996775af841578ead235540eb383f114b4e0eb00Christopher Wileynamespace aidl { 27996775af841578ead235540eb383f114b4e0eb00Christopher Wileynamespace tests { 28996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 29996775af841578ead235540eb383f114b4e0eb00Christopher WileySimpleParcelable::SimpleParcelable(const std::string& name, int32_t number) 30996775af841578ead235540eb383f114b4e0eb00Christopher Wiley : name_(name.c_str(), name.length()), 31996775af841578ead235540eb383f114b4e0eb00Christopher Wiley number_(number) {} 32996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 33996775af841578ead235540eb383f114b4e0eb00Christopher Wileystatus_t SimpleParcelable::writeToParcel(Parcel* parcel) const { 34996775af841578ead235540eb383f114b4e0eb00Christopher Wiley status_t status = parcel->writeString16(name_); 35996775af841578ead235540eb383f114b4e0eb00Christopher Wiley if (status != OK) { 36996775af841578ead235540eb383f114b4e0eb00Christopher Wiley return status; 37996775af841578ead235540eb383f114b4e0eb00Christopher Wiley } 38996775af841578ead235540eb383f114b4e0eb00Christopher Wiley status = parcel->writeInt32(number_); 39996775af841578ead235540eb383f114b4e0eb00Christopher Wiley return status; 40996775af841578ead235540eb383f114b4e0eb00Christopher Wiley} 41996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 42996775af841578ead235540eb383f114b4e0eb00Christopher Wileystatus_t SimpleParcelable::readFromParcel(const Parcel* parcel) { 43996775af841578ead235540eb383f114b4e0eb00Christopher Wiley status_t status = parcel->readString16(&name_); 44996775af841578ead235540eb383f114b4e0eb00Christopher Wiley if (status != OK) { 45996775af841578ead235540eb383f114b4e0eb00Christopher Wiley return status; 46996775af841578ead235540eb383f114b4e0eb00Christopher Wiley } 47996775af841578ead235540eb383f114b4e0eb00Christopher Wiley return parcel->readInt32(&number_); 48996775af841578ead235540eb383f114b4e0eb00Christopher Wiley} 49996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 50996775af841578ead235540eb383f114b4e0eb00Christopher Wileystd::string SimpleParcelable::toString() const { 51996775af841578ead235540eb383f114b4e0eb00Christopher Wiley return StringPrintf("%s(%d)", String8(name_).string(), number_); 52996775af841578ead235540eb383f114b4e0eb00Christopher Wiley} 53996775af841578ead235540eb383f114b4e0eb00Christopher Wiley 54996775af841578ead235540eb383f114b4e0eb00Christopher Wiley} // namespace tests 55a94c9593a4316ef3147a208a3087010bab256735Samuel Tan} // namespace aidl 56996775af841578ead235540eb383f114b4e0eb00Christopher Wiley} // namespace android 57