1 /* 2 * Copyright (C) 2016 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 18 package com.android.settings.search2; 19 20 import android.os.BadParcelableException; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.util.Log; 24 25 import java.io.StreamCorruptedException; 26 27 /** 28 * Utility class to Marshall and Unmarshall the payloads stored in the SQLite Database 29 */ 30 public class ResultPayloadUtils { 31 32 private static final String TAG = "PayloadUtil"; 33 marshall(ResultPayload payload)34 public static byte[] marshall(ResultPayload payload) { 35 Parcel parcel = Parcel.obtain(); 36 payload.writeToParcel(parcel, 0); 37 byte[] bytes = parcel.marshall(); 38 parcel.recycle(); 39 return bytes; 40 } 41 unmarshall(byte[] bytes, Parcelable.Creator<T> creator)42 public static <T> T unmarshall(byte[] bytes, Parcelable.Creator<T> creator) { 43 T result; 44 Parcel parcel = unmarshall(bytes); 45 result = creator.createFromParcel(parcel); 46 parcel.recycle(); 47 return result; 48 } 49 unmarshall(byte[] bytes)50 private static Parcel unmarshall(byte[] bytes) { 51 Parcel parcel = Parcel.obtain(); 52 parcel.unmarshall(bytes, 0, bytes.length); 53 parcel.setDataPosition(0); 54 return parcel; 55 } 56 } 57