11dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze/* 22078bc2358031ef3a191900d9036daf4251911c1Matthew Fritze * Copyright (C) 2017 The Android Open Source Project 31dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * 41dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * Licensed under the Apache License, Version 2.0 (the "License"); 51dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * you may not use this file except in compliance with the License. 61dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * You may obtain a copy of the License at 71dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * 81dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * http://www.apache.org/licenses/LICENSE-2.0 91dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * 101dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * Unless required by applicable law or agreed to in writing, software 111dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * distributed under the License is distributed on an "AS IS" BASIS, 121dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * See the License for the specific language governing permissions and 141dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * limitations under the License. 151dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * 161dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze */ 171dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze 182078bc2358031ef3a191900d9036daf4251911c1Matthew Fritzepackage com.android.settings.search; 191dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze 201dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport android.os.Parcel; 211dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzeimport android.os.Parcelable; 221dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze 231dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze/** 241dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze * Utility class to Marshall and Unmarshall the payloads stored in the SQLite Database 251dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze */ 261dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritzepublic class ResultPayloadUtils { 271dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze 281dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze private static final String TAG = "PayloadUtil"; 291dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze 301dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze public static byte[] marshall(ResultPayload payload) { 311dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze Parcel parcel = Parcel.obtain(); 321dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze payload.writeToParcel(parcel, 0); 331dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze byte[] bytes = parcel.marshall(); 341dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze parcel.recycle(); 351dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze return bytes; 361dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze } 371dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze 381dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze public static <T> T unmarshall(byte[] bytes, Parcelable.Creator<T> creator) { 391dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze T result; 401dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze Parcel parcel = unmarshall(bytes); 411dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze result = creator.createFromParcel(parcel); 421dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze parcel.recycle(); 431dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze return result; 441dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze } 451dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze 461dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze private static Parcel unmarshall(byte[] bytes) { 471dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze Parcel parcel = Parcel.obtain(); 481dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze parcel.unmarshall(bytes, 0, bytes.length); 491dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze parcel.setDataPosition(0); 501dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze return parcel; 511dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze } 521dec073528352fcf036c5ba52d5d535ba32c472cMatthew Fritze} 53